IOS Releasing object too early - possible confusion with Autorelease and Copy?

When you copy objects (and to do so that object must conform to the NSCopying Protocol but that's the case of NSArray ) it is exactly as if you were init ializing it for the first time with predifined values So it is your responsability to release objects that have been copied Thefore you must do : self. AResults = thisSearch. AResults copy ... thisSearch release; // When you release thisSearch this will not affect aResults ... // then you can either do: self.

AResults autorelease; // but then do not release it later on // or self. AResults release; // when you're done with it However I doubt this will solve you memory issues. By over autoreleasing (and still releasing things) you might have completely corrupted your application memory management To try to fix it, try to analyze your project and see what comes up Also I attach the Apple Memory Management link that one should read monthly until it becomes second nature.

When you copy objects (and to do so that object must conform to the NSCopying Protocol but that's the case of NSArray) it is exactly as if you were initializing it for the first time with predifined values. So it is your responsability to release objects that have been copied. Thefore you must do : self.

AResults = thisSearch. AResults copy ... thisSearch release; // When you release thisSearch this will not affect aResults ... // then you can either do: self. AResults autorelease; // but then do not release it later on // or self.

AResults release; // when you're done with it However I doubt this will solve you memory issues. By over autoreleasing (and still releasing things) you might have completely corrupted your application memory management. To try to fix it, try to analyze your project and see what comes up.

Also I attach the Apple Memory Management link that one should read monthly until it becomes second nature.

Aaaah I should have run Analyze! I ran that, and it pointed me to an NSDicitonary which I was autoreleasing, and told me the reference counter was already 0, because I was assigning that dictionary to an array which was also autorelease - so I suppose it was trying to release that dicitonary when the array it was in was already gone – Skeater Sep 1 at 8:28.

This wasn't happening to me before, but I realised I was leaking memory, so I went autorelease crazy, and added lots of autorelease to my Search class. But not my FirstViewController class. So if I use Copy, does it not actually make a copy of the object, does it just increase the reference counter?

So when I destroy Search, am I destroying the results array in there, and therefore destroying what the FirstViewController is trying to access for the table view? Sorry if that doesn't make much sense, I'm not feeling very with it today.

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