开发者

Memory leaks in UIView class

I have created customize UIView with following code .....it's running with no issue....but when i check for Memory leaks...it shows leaks at point where i have made comment ...this is subclass of Uiview. Please help me...

-(id) initWithLabel:(NSString*)labelName{

self = [super init];
if (self) {
    self.layer.cornerRadius=8.0f;
    self.layer.borderColor=[UIColor whiteColor].CGColor;
    self.layer.borderWidth=2.0f;
/*memory leaks 28.6% */ [self setBackgroundColor:[UIColor colorWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1]];
    [self setFrame:CGRectMake(86, 168, 160, 77)];
    [self setAlpha:1];

    UILabel *label = [[UILabel alloc] initWithFrame:C开发者_高级运维GRectMake(20, 28, 75, 21)];
    [label setBackgroundColor:[UIColor  clearColor]];
    [label setTextAlignment:UITextAlignmentLeft];
    [label setTextColor:[UIColor whiteColor]];
    [label setFont:[UIFont fontWithName:@"Helvetica" size:17]];//memory leak 57%
    [label setText:labelName];
    [label setOpaque:NO];//memory leak
    [self addSubview:label];
    [label release];

    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(108, 22, 37, 37)];
    [activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [activityIndicator setBackgroundColor:[UIColor clearColor]];
    [activityIndicator setHidesWhenStopped:YES];
    [self addSubview:activityIndicator];
    [activityIndicator release];
}
return self;

}


try this

  UIColor *myColor = [[UIColor alloc] initWithRed:51.0/255 green:51.0/255 blue:51.0/255 alpha:1];

  [self setBackgroundColor:myColor];

  [myColor release];

Hey man that is not memory leaks. that is autoreleased objects.so dont worry about them.apple wont reject urs.the condition is if u use alloc,init,new or retain then only u have responsibility to release.so leave it.otherwise do like above by alloc and init then release it .that'st it

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜