UIView 类中的内存泄漏
我已经使用以下代码创建了自定义 UIView ....它运行没有问题....但是当我检查内存泄漏时...它在我发表评论的地方显示泄漏...这是 Uiview 的子类。 请帮我...
-(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:CGRectMake(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;
}
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:CGRectMake(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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
嘿伙计,这不是内存泄漏。那是自动释放的对象。所以不要担心它们。苹果不会拒绝你的。条件是如果你使用alloc,init,new或retain,那么只有你有责任释放。所以离开它。否则就像上面的alloc和init一样释放它。就这样
try this
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