Objects deallocation question?

Short answer: For any property that you declare as retain (or copy ), you should set its value to nil in your dealloc method. Properties that are declared on other objects and fields which you do not retain yourself you do not need to worry about.

Short answer: For any property that you declare as retain (or copy), you should set its value to nil in your dealloc method. Properties that are declared on other objects and fields which you do not retain yourself you do not need to worry about.

– Matubo Jul 4 at 0:29 @Matubo - Then I'm not sure what you're asking for. I thought you wanted to know which objects you need to release? If so, then the answer is "only the properties that you've declared as retain/copy, and any other objects that you have manually retained in your code".

– aroth Jul 4 at 0:30 My reply was on your first version of answer, that was without the second phrase. :) – Matubo Jul 4 at 0:31 You can also just not worry about the difference and set all your properties to nil in your dealloc. If they're set as retain or copy then that'll cause the setter to release them.

If they're set as assign then the setter won't do anything with respect to memory management. – Tommy Jul 4 at 2:34.

Your interface will never provide enough information about what you should or shouldn't release (but it will provide clues). You could have all the ivars and properties you declared above, but if you haven't initialised them and/or accessed their properties, there is never going to be an object to release in the first place. Rule of thumb is: 1) If you create, copy or retain an object, you are responsible for releasing it.2) See rule #1 above.In practice, here are some examples: @implementation... ... pic_one = UIImage imageNamed:@"test.

Png"; ... @end pic_one is declared as an ivar but is assigned to an autoreleased object. You don't have to release it. Another example: @implementation.... ... self.

Pic_one = UIImage imageNamed:@"test. Png"; ... @end You assigned this UIImage object via its assessor/property which is declared as retain, so you are responsible for releasing it."Behind the scenes", here's what happens when you assign the object via its property (example is for properties declared as retain, copy will be slightly different but same principle). - (void)setPic_One:(UIImage*)newImage { if (pic_One!

= newImage) { newImage retain; pic_One release; pic_One = newImage; } } And a last one: UIImage *testImage = UIImage alloc initWithImage:@"test. Png"; self. Pic_one = testImage; testImage release; In this case you are alloc'ing/init'ing (creating) an UIImage object, so you are responsible for releasing it.

At the same time you are also assigning it to a property declared as retain so it is your responsibility to release it too when you are done with it (usually in your dealloc method).

Yes, these are the basics of memory management, that are ABC to every starter. But the moment, that I want to clarify is: firstPicContainer. Image = self.

Pic_one; UIImageView is declared in iVar, its property is assigned to a retained value. Should it then be released in -dealloc? – Matubo Jul 5 at 4:10 The problem is in the dualism of the situation: on one hand the property value is retained by me, the property 'image' of UIImageView is retained by iself: '@property(nonatomic, retain) UIImage *image'.

Everything shows, that I should release it. But on the other hand: I didn't break the memory rule: never used 'alloc''copy''new'functions to create an instance. And the UIImageView is owned by the view as its subview, so the view is responsible to release it, and I shouldnt.

I'm really desperate. – Matubo Jul 5 at 4:48 To answer your first comment re: firstPicContainer. Image = self.

Pic_one, firstPicContainer should not be released because you are not accessing it through its property but directly via the ivar. BUT because the firstPicContainer is also declared as an IBOutlet, it will be retained by the view when your nib is loaded (if you have connected it to an UIImageView object on Interface Builder). In this case you will have to release firstPicContainer because interface builder will access it via its property (and it is also recommended that you set it to nil on viewDidUnload).

– Rog Jul 5 at 5:18 In addition to the comment above, you should probably post an example with interface and implementation files to clarify what you are asking. – Rog Jul 5 at 5:31.

Your interface will never provide enough information about what you should or shouldn't release (but it will provide clues).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions