Search code examples
objective-ccocoamemory-managementretaincount

NSMutableArray getting released?


I have a NSMutableArray whose property is (nonatomic, retain), and it's getting released for some reason, here's the code when I assign it (tableData is the NSMutableArray):

tableData = [[[NSMutableArray alloc] init] autorelease];

When I alloc it, it's retain count is 1. When I assign it to tableData, it's retain count is 2. Then with auto release, at the end of runloop it should go to 1 (which is what I want). But this doesn't happen. Later on, when I reference it and run a method, I get random objects (last time it was UITabBarSwappableImageView) and it says unrecognized selector sent. Which makes sense...the object is being released and some other object is taking it's place...But why is it being released? Thanks.


Solution

  • Did you use the dot syntax? If not, the synthesized setter is not used thus the reference is not retained.

    It should be assigned like this:

    self.tableData = [[[NSMutableArray alloc] init] autorelease];