KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm new to memory managed code but I get the idea pretty well. On taking my app through the leaks tool in XCode, I noticed I only had to clean up my custom objects, but not dynamically created arrays for example, so I figured those data types are autoreleased - makes sense since I only had to release the arrays I used as properties that had a (retain) on them. Then I noticed something peculiar : I was getting a leak on a certain array initialized like this : NSMutableArray *removals = [NSMutableArray new]; but not a similar one NSMutableArray *removals = [NSMutableArray arrayWithCapacity:9]; Now, the reason one was set up with "new" is that it could have 0-99 items in it, whereas the other one I knew was going to always be 9. Since both arrays are passed to the same method later based on user interaction, I was either getting a leak if I did not release at the end of the method, or an exception if I did! I changed the first array to NSMutableArray *removals = [NSMutableArray arrayWithCapacity:99]; and I get no leaks and don't have to release anything. Can anyone explain?
Tags (comma-separated)
Save Edits
Cancel