Memory leaks NSmutableArray的问题 -(void)createTileOnScreen:(CGRect)rect { myArray=[[NSMutableArray alloc]init]; CGRect界限=rect; CGRect myRect=CGRectMake(bounds.origin.x,bounds.origin.y, (int)(界限尺寸宽度/11), (int)(bounds.size.height/10); 对于(int i=0;i
当多次调用createtileonscreen时,我发现分配量一直在增加。你能告诉我怎么取消分配吗Memory leaks NSmutableArray的问题 -(void)createTileOnScreen:(CGRect)rect { myArray=[[NSMutableArray alloc]init]; CGRect界限=rect; CGRect myRect=CGRectMake(bounds.origin.x,bounds.origin.y, (int)(界限尺寸宽度/11), (int)(bounds.size.height/10); 对于(int i=0;i,memory-leaks,uiview,memory-management,nsmutablearray,Memory Leaks,Uiview,Memory Management,Nsmutablearray,当多次调用createtileonscreen时,我发现分配量一直在增加。你能告诉我怎么取消分配吗 myArray没有任何泄漏,并将其从超级视图中删除。myArray是如何定义的?它是一个实例变量,与之对应的是@propoEntry和@synthesis吗 应该是 - (void)createTileOnScreen:(CGRect)rect { myArray = [[NSMutableArray alloc] init]; CGRect bounds = re
myArray没有任何泄漏,并将其从超级视图中删除。myArray是如何定义的?它是一个实例变量,与之对应的是@propoEntry和@synthesis吗 应该是
- (void)createTileOnScreen:(CGRect)rect
{
myArray = [[NSMutableArray alloc] init];
CGRect bounds = rect;
CGRect myRect = CGRectMake(bounds.origin.x,bounds.origin.y,
(int)(bounds.size.width / 11),
(int)(bounds.size.height / 10));
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 11; j++) {
int index = 10 * i + j;
Liv *myTile = [[Liv alloc] initWithFrame:myRect withIndex:index];
float width = (1.0 / 11);
float height = (1.0 / 10);
[myTile setImageSection:CGRectMake((j / 11),
(1.0 - ((i+1) / 10)),
width,
height)];
[self.rotationView addSubview:myTile];
[myArray addObject:myTile];
[myTile release];
myRect.origin.x += myRect.size.width;
}
myRect.origin.x = bounds.origin.x;
myRect.origin.y = myRect.origin.y + myRect.size.height ;
}
}
#import "Liv.h"
@implementation Liv
@synthesize index;
- (id)initWithFrame:(CGRect)frame withIndex:(int)index_ {
if (self = [super initWithFrame:frame]) {
self.index = index_;
self.backgroundColor = [UIColor blackColor];
fadingAnimationDuration = 2.0;
}
return self;
}
- (id)initWithFrame:(CGRect)frame withIndex:(int)index_ WithColor:(UIColor *)aColor {
if (self = [self initWithFrame:frame withIndex:index_]) {
self.backgroundColor = aColor;
}
return self;
}
有相应的
self.myArray = [NSMutableArray array];
在.h文件中。那你就没事了。根据你现在的情况,每次
@property(retain) myArray;
调用时,myArray持有的旧NSMutableArray在被分配给myArray的新NSMutableArray替换时泄漏。Move
- (void)createTileOnScreen:(CGRect)rect
出于
myArray = [[NSMutableArray alloc] init];
会很好地释放你的瓷砖。但您可能希望在发布和发布之前遍历数组
- (void)createTileOnScreen:(CGRect)rect
[myArray release];
[[myArray objectAtIndex:index] removeFromSuperview];