gpt4 book ai didi

iphone - 关于内存泄漏问题

转载 作者:行者123 更新时间:2023-12-03 21:20:55 25 4
gpt4 key购买 nike

我是 iPhone 开发新手。我在以下代码中遇到内存泄漏问题。如果有人知道为什么会发生这种情况,请帮助我。

for(int i=0;i<size;i++)
{
NSString *CellIdentifier1;
if(universalApp==2)
{
CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];

//NSLog(@">>>>> Creating image >>>>>>>>");
cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];


[imgViewArray addObject:cell.thumbImageView];
[cell.thumbImageView release];

}

最佳答案

此外,使用自动释放池,

for(int i=0;i<size;i++) {


NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

...
cell.thumbImageView = [[[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)] autorelease];
...

[pool release];
}

检查imgViewArray,你知道,添加到NSMutableArray的对象的保留计数会增加1。

关于iphone - 关于内存泄漏问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4930278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com