我的代码是这样的:
CGImageRef ImageCreateWithFile(NSString *filePath)
{
if(NULL == filePath)
return NULL;
NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];
if(NULL == data)
return NULL;
CGImageSourceRef isrc = CGImageSourceCreateWithData((CFDataRef)data, NULL);
// [data release];
CGImageRef image = CGImageSourceCreateImageAtIndex(isrc, 0, NULL);
CFRelease(isrc);
isrc = nil;
[data release];
data = nil;
return image;
}
- (IBAction)addClick:(id)sender
{
CGImageRef image = ImageCreateWithFile(@"/Users/user/t.jpg");
if(NULL != image)
_imageList.push_back(image);
}
- (IBAction)removeClick:(id)sender
{
if(_imageList.size() > 0)
{
CGImageRef image = _imageList[0];
CGImageRelease(image);
image = nil;
_imageList.erase(_imageList.begin());
}
}
imageList
声明如下:
std::vector<CGImageRef> _imageList;
该程序是为测试释放方法而编写的CGImageRef
。当我添加一些图像时,我在活动监视器中看到程序的内存使用率有规律地上升,但是当我通过该remove
方法删除一个或多个图像后,内存从未下降。不知道为什么release方法不起作用?有什么帮助吗?谢谢!!!