我创建一个位图背景下,在我的代码中有这样的:该方法返回的CGContextRef对象如何发布?
bitmapData = malloc(bitmapByteCount);
context = CGBitmapContextCreate (bitmapData,
pixelsWidth,
pixelsHeight,
8, // bits per component
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedFirst);
之前,我想我必须释放位图数据。在返回context
之前,我可以安全地拨打free(bitmapData)
吗?
难道这不是真的吗?如果方法名称中有“创建”,则必须自动释放它,以便接收方不必担心内存管理。只有在方法名称或“alloc”中为“新”时,您才必须手动释放。至少这是我学到了什么;) – openfrog 2010-09-23 09:36:49
这个问题:http://stackoverflow.com/questions/870243/releasing-core-foundation-object-references解释关于核心基础释放对象的几件事情。 Core Foundation没有autorelease的概念。 – Jasarien 2010-09-23 11:06:39
从这个问题的答案中我链接到:“由于在Core Foundation中没有autorelease等价物,如果你从方法返回一个引用,返回数组而不释放它,你应该(除非你是邪恶的),那么在方法名中包含“create”以向调用者指示他们现在拥有对返回对象的引用。“ – Jasarien 2010-09-23 11:08:41