开发者

Potential leak of an object allocated for Activity indicator window

开发者 https://www.devze.com 2023-02-18 12:13 出处:网络
I use ActivityIndicatorC 开发者_JAVA百科class in the application delegate file and alloc object for it but here i get memory leak,

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消