Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
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.
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?
Replies
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSorry, I wasn't sure if the code would help. But here it is.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeWhenever 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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIn Section.h I have:
@property (nonatomic, retain) NSMutableArray *tiles;
In Section.m I have:
- (void) dealloc {
[tiles release];
[super dealloc];
}
Elsewhere in my code, after the sections array is initialized, I have this:
Is that correct, or could that be part of the problem?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThen 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.
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.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- (id) copyWithZone: (NSZone *) zone {Section *sectionCopy = [[Section allocWithZone: zone] init];
sectionCopy.solved = solved;
sectionCopy.sectionRow = sectionRow;
sectionCopy.sectionCol = sectionCol;
sectionCopy.tiles = [[NSMutableArray alloc] init];
for( Tile *aTile in tiles ) {
Tile *tileCopy = [aTile copy];
[sectionCopy.tiles addObject: tileCopy];
[tileCopy release];
}
//[sectionCopy.tiles release];
return sectionCopy;
}
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?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThat creates an autoreleased array, but property will retain it. Now you don't need to call [sectionCopy.tiles release] here.
If you make this change and your app starts crashing then you are over-releasing "tiles" somewhere else.
Remember that the leaks tool tells you where the leaked object was created, *not* the line that is wrong, broken, or "causing" the leak.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome