简体   繁体   中英

MKMapView initWithFrame not releasing memory with ARC

I've been using instruments to find allocations that aren't being released properly. I have MKMapViewDelegate that adds a map via a instance method after it has been instantiated. I can see in the call tree that this method keeps retaining about 300KB of memory, after the ViewDelegate is released. I commented out the meat of the code and it stills maintains the memory with just this line:

self.map = [[MKMapView alloc] initWithFrame:CGRectMake(10, 210, 300, 125)];

I look in the object list and the MKMapView itself isn't living, but as I keep creating new ViewDelegates, that memory keeps adding up. Here is how map is defined:

@property (strong, nonatomic)        MKMapView *map;

The map's delegate is set to nil, as well as the reference on the ViewDelegate's dealloc

self.map.delegate = nil;
self.map = nil;

Once you set the delegate to nil, there are no longer any pointers, and iOS will release it when it wants to. iOS may not release the memory immediately after setting it to nil.

Remember, that you are removing the pointer by setting it to nil, but the object still remains on the heap, basically doing nothing, until something else gets allocated there.

(I'm assuming you also removed the MKMapView from its superview using [self.map removeFromSuperView] ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM