开发者

memory issue in the method

I am running application in leak's i found 20% for memory issue.

-(void)createLabel{

iconTitle=[[UICustomLable alloc]initWithMenuFrame:CGRectMake(10, 35, 80, 60) text:TAB_LANDSCAPE_WALL];
    [myView addSubview:wbgImg];
    [myView addSubview:iconTitle];
    iconTitle=nil;


    iconTitle=[[UICustomLable alloc]initWithMenuFrame:CGRectMake(10, 35, 80, 60) text:TAB_WALL];
    [myView addSubview:wbgImg];
    [myView addSubview:iconTitle];
    iconTitle=nil;
}

even i release it also

-(void)createLabel{

iconTitle=[[UICustomLable alloc]initWithMenuFrame:CGRectMake(10, 35, 80, 60) text:TAB_LANDSCAPE_WALL];
    [myView addSubview:wbgImg];
    [myView addSubview:iconTitle];
        [iconTitle release]; 
    iconTitl开发者_如何学Goe=nil;


    iconTitle=[[UICustomLable alloc]initWithMenuFrame:CGRectMake(10, 35, 80, 60) text:TAB_WALL];
    [myView addSubview:wbgImg];
    [myView addSubview:iconTitle];
    [iconTitle release]; 
        iconTitle=nil;
}

I am calling this method in viewdidload

[self createLabel];

@All

can any one help me out with this issue.


You should always release an object when you call alloc and init, copy or new.

You can find some memory leak when using the analyze. Goto product -> analyze.


Check if your UICustomLable class doesn't contain a memory leak and use your second solution with the release keyword. Also delete the app from the device/simulator and clean the project (cmd+shift+k) and then rebuild it and try it again. :)


If your UICustomLable has no memory leaks then it seems you allocate memory for "wbgImg" in your init method. Make sure you release it in dealloc.

In iOS 5.0 there is a new technology called ARC (Automatic Reference Counting), basically you won't need to worry about this in the future.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜