Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

AndyCodez

macrumors regular
Original poster
Aug 6, 2009
187
0
Ok, I have been doing a few views like this where in one class i will:

Code:
myView *view = [[myView alloc] initwithFrame: blah];


then within myView I get done doing what ever i'm doing and then i do [self release]. Will this properly deallocate the memory?

It doesn't seem that dealloc gets called in said class :/
 
As far as I know, [self release] isn't recommended under any circumstances. In this case, your view would likely be disappearing before the result may be displayed. The views stability is highly questionable. The owner, the object or method, that created the instance of your view is the one responsible for releasing the view.

If your view is being added as a subview to another view, then the minimum code might look like this;

Code:
MySubClassView * myview = [[MySubClassView alloc] initWithFrame: aRect];
[myParentview addsubview: myview];
[myview release];

As far as knowing if dealloc is getting called, put in an NSLog() to see if it is. Simple solution.

Go read Learn Objective-C over at Cocoadevcentral.com.
 
Lol yes of course case sensitive. But say i don't want to create a property for said item. So I want to release said item later. So i have a delegate method like so

Code:
- (void) releaseItem:(id) item
{
      [item release];
}

is this fair or should I not do this either?

But then again I'm allocing
Code:
Item *item = [[Item alloc] initWithArray:arr];
[item addViewto:self.view];  //adding view to parent (method within the Item class actually adds Item view to view that is passed to the method.)
[item release];
Would this be correct?
 
Your coding thought process is totally messed up. Go buy a decent Objective-C book. Hopefully it will set you straight. I'm not trying to be mean, but you are making stuff up that isn't required.

Your delegate idea serves no purpose since you can just do
Code:
[item release];
There is no need for the extra call since you already know the object, 'item', that you want to release.

Ditto for your idea about creating a method in your custom view to add it to a parent view. That is a complete waste.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.