Xcode 指示对象潜在泄漏
首先我是一个n00b。经过长时间的尝试和研究,我决定寻求一些外部帮助。 我的项目: 我为孩子们做了一本书。现在我正在分析我的代码并尝试消除一些泄漏(一段时间后发生 1 级 + 2 级崩溃)。 这是我的代码
- (void)loadView {
_oben = YES;
_unten = NO;
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIImage *cover = [UIImage imageNamed:@"Umschlag.png"]; //Here it says "Potential leak..
//..allocated on line 141 (thats at self.view = [[UIView alloc] initWithFrame:...
image = [[UIImageView alloc] initWithImage:cover];
image.frame = CGRectMake(0, 0, 768, 1024);
[self.view addSubview:image];
[image release];
UITextView *text1 = [[UITextView alloc] initWithFrame:CGRectMake(184, 700, 400, 100)];
text1.backgroundColor = [UIColor clearColor];
text1.textAlignment = UITextAlignmentCenter;
text1.text = NSLocalizedString(@"CoverTextKey1", nil);
[self.view addSubview:text1];
[text1 release];
[self addButtonNext];
[self addSwipeDown];
[self addSwipeUp];
}
有什么想法吗? 如果有人能帮助我,那就太酷了! 预先感谢普朗基
First of all i am a n00b. After long time of trying and research i decided to get some external help.
My Project:
i made a book for children. Now i am analyzing my code and try to get rid of some leaks (level 1 + 2 Crash after a while).
Here is my Code
- (void)loadView {
_oben = YES;
_unten = NO;
self.view = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
UIImage *cover = [UIImage imageNamed:@"Umschlag.png"]; //Here it says "Potential leak..
//..allocated on line 141 (thats at self.view = [[UIView alloc] initWithFrame:...
image = [[UIImageView alloc] initWithImage:cover];
image.frame = CGRectMake(0, 0, 768, 1024);
[self.view addSubview:image];
[image release];
UITextView *text1 = [[UITextView alloc] initWithFrame:CGRectMake(184, 700, 400, 100)];
text1.backgroundColor = [UIColor clearColor];
text1.textAlignment = UITextAlignmentCenter;
text1.text = NSLocalizedString(@"CoverTextKey1", nil);
[self.view addSubview:text1];
[text1 release];
[self addButtonNext];
[self addSwipeDown];
[self addSwipeUp];
}
Any ideas?
It would be really cool if anyone could help me!
Thanks in advance Planky
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该行是过度保留对象,因为
alloc-init
返回一个保留对象(+1),并且属性设置器也保留该对象(+2)。您可以使用临时变量...
...或 autorelease 来解决此问题:
That line is over-retaining the object because
alloc-init
returns a retained object (+1) and the property setter also retains the object (+2).You can use a temporary variable...
...or autorelease to fix this:
请改用
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
或- (id)initWithContentsOfFile:(NSString *)path
。它们不会缓存图像,imageNamed:
会缓存图像。Use
+ (UIImage *)imageWithContentsOfFile:(NSString *)path
or- (id)initWithContentsOfFile:(NSString *)path
instead. They don't cache the image,imageNamed:
does.