我在循环的每次迭代中创建一个对象for
。但是从不调用 dealloc 函数。它不应该在每次迭代时发布吗?我正在使用 ARC,并且我已停用 NSZombies。我没有看到任何循环引用。从 xcode 运行内存泄漏工具它不会显示任何泄漏,但是该类的指针内存永远不会被释放并且dealloc
调用永远不会完成。知道为什么会发生这种情况吗?
谢谢!
for(int i=0; i<10; i++)
{
//calculate the hog features of the image
HogFeature *hogFeature = [self.image obtainHogFeatures];
if(i==0) self.imageFeatures = (double *) malloc(hogFeature.totalNumberOfFeatures*sizeof(double));
//copy the features
for(int j=0; j<hogFeature.totalNumberOfFeatures; j++)
self.imageFeatures[i*hogFeature.totalNumberOfFeatures + j] = hogFeature.features[j];
}
类HogFeature
声明如下所示:
@interface HogFeature : NSObject
@property int totalNumberOfFeatures;
@property double *features; //pointer to the features
@property int *dimensionOfHogFeatures; //pointer with the dimensions of the features
@end
和实施:
@implementation HogFeature
@synthesize totalNumberOfFeatures = _totalNumberOfFeatures;
@synthesize features = _features;
@synthesize dimensionOfHogFeatures = _dimensionOfHogFeatures;
- (void) dealloc
{
free(self.features);
free(self.dimensionOfHogFeatures);
NSLog(@"HOG Deallocation!");
}
@end
最后,对类别obtainHogFeatures
内部的调用如下所示:UIImage
- (HogFeature *) obtainHogFeatures
{
HogFeature *hog = [[HogFeature alloc] init];
[...]
return hog;
}