I’ve written an app with a custom Search class in it. This builds up an array of results.
I then assign that array into my FirstViewController class, and reload a table view which has the results array assigned to it
self.aResults = [thisSearch.aResults copy]
...
[[self searchResults] reloadData];
Shortly after doing that I’m releasing thisSearch
[thisSearch release];
This all works fine, and shows the the results table, but if I scroll down the table and look at the rows below they are all blank, then as I scroll back up the app crashes when it reloads the recycled table cells.
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.
When you
copyobjects (and to do so that object must conform to theNSCopyingProtocol but that’s the case ofNSArray) it is exactly as if you wereinitializing it for the first time with predifined values.So it is your responsability to
releaseobjects that have beencopied.Thefore you must do :
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.