objective c - Deallocating object doesn't work -


maybe i'm working long have problem... let's make abstract, real names not important.

i've 20+ classes inheriting superclass, car

@interface car : nsobject; @interface volvo : car; @interface bmw : car; etc... 

in game class i've property volvo, bmw

@property (nonatomic, strong) volvo *volvo; @property (nonatomic, strong) bmw *bmw; @property (nonatomic, strong) car *activecar; 

i create object dynamicaly , storing activecar in property activecar

_bmw = [[bmw alloc] init];     _activecar = _bmw; 

now in restart method want able nil active car, it's not wokring though in log see both pointing on same address:

_activecar = nil; // dealloc on bmw , car not called // _bmw = nil; // dealloc called on bmw , car class 

how can manage that? solution?

if ([_activegame iskindofclass:[bmw class]]) _bmw = nil; 

if want destroy bmw when destroy activecar, there's no sense in keeping bmw around ivar anyway.

_activecar = [[bmw alloc] init]; 

your current implementation wont nil out bmw because self.bmw still has reference it.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -