I use ActivityIndicatorC 开发者_JAVA百科class in the application delegate file and alloc object for it but here i get memory leak,
self.ActIndicator=[[ActivityIndicatorC alloc] initwithWindow:window];
I release ActIndicator this object in the dealloc section but till i am get same potential leak for the above mention code.
Any solution any one can suggest for it.
the object is retained twice. When using self.ActIndicator =
you invoke the setter, which the compiler created for you by using the @property(retain,...)
you put in your interface.
self.ActIndicator=[[ActivityIndicatorC alloc] initwithWindow:window];
^ retainCount + 1 ^^^^^ and +1 because of this.
you could write
self.ActIndicator = [[[ActivityIndicatorC alloc] initwithWindow:window] autorelease];
or
ActIndicator = [[ActivityIndicatorC alloc] initwithWindow:window];
And you should change the name to actIndicator or (even better) activityIndicator. Only class names should start with a capital letter.
if ActIndicator is set to retain property . then there is leak in .h file make @property(nonatominc ,retain) to @property(nonatominc ,assign) or
ActivityIndicatorC *theActivity= [[ActivityIndicatorC alloc] initwithWindow:window];
self.ActIndicator=theActivity;
[theActivity release];
You'll have to manually release objects created with alloc-init. So you should write a [ActIndicator release]; or just autorelease it.
精彩评论