In my code I initialize the myObjects array with properties set on both the myObjects and the subObjects, everything working fine. Then, at some future point, during some code that has nothing to do with the myObjects array, the subObjects all of a sudden lose their data. What could cause this?
Is there something special you have to do when you have two NSMutableArrays of custom objects nested within each other? I'm getting all kinds of data loss/overwriting. Plus, Instruments is telling me I have memory leaks even though I have all the right release calls. Anyone have a hint as to whats happening? Thanks.
Is there something special you have to do when you have two NSMutableArrays of custom objects nested within each other? I'm getting all kinds of data loss/overwriting. Plus, Instruments is telling me I have memory leaks even though I have all the right release calls. Anyone have a hint as to whats happening? Thanks.
You show no code and claim no leaks though apparent Instruments thinks differently. How is someone supposed to help you?
I was able to fix my problem, by removing the release calls to "sec" and "aTile". Of course, now I have memory leaks. Can anyone shed some light on what's happening? Thanks.
I was able to fix my problem, by removing the release calls to "sec" and "aTile". Of course, now I have memory leaks. Can anyone shed some light on what's happening? Thanks.
What does the property line or setter look like for tiles?
The code you posted looks correct, *assuming* that the "sections" array does not get leaked, that you've written a proper dealloc method for the Section class, and that "tiles" is a retain property. Removing those releases is not correct, as you figured out.
Whenever you see leaks make sure you tackle the collection classes and parent objects first. If you forget to release one array and it contains 50 strings, you'll see 51 leaks in the leaks instrument. When you fix the array leak they all go away.
Is that correct, or could that be part of the problem?
Yoinks! That's not correct. You're creating a new pointer, and alloc+init a new Section for it to point to.
Then you point the pointer (sec) at a different object, leaking one you just alloc'd.
Then you release the object that you got from the sections array, even though you never retained it. I am surprised that doesn't crash your program.
Code:
Section *sec =[sections objectAtIndex: index];
// do stuff with sec
// no need to release; we didn't retain it.
Your snippet indicates a confusion between pointers and objects. You can have two pointers to the same object, and you don't need to alloc a new object every time you have a new pointer. That confusion is probably the root of all of your issues.
The alloc-ing of the Mutable Array seems to be giving me a leak, but if I uncomment the release, my app crashes, and if I don't alloc the array then I can't add objects to it. What is the solution here?