I created a simple program to test the retain/release methods in Objective-C memory management. As I understand of ObjC memory management, I expect that a object with retain count = 1 on which I callrelease get the retain count decremented to zero and then released. But this test program show that after the first release I still get retain count = 1:
// TestClass.h
#import <Cocoa/Cocoa.h>
@interface TestClass : NSObject {
}
@end
// TestClass.m
#import "TestClass.h"
@implementation TestClass
@end
// RetainRelease.m
#import <Foundation/Foundation.h>
#include "TestClass.h"
void dumpRetain(id o);
int main (int argc, const char * argv[]) {
TestClass *s = [[TestClass alloc] init];
dumpRetain(s);
[s release];
dumpRetain(s);
}
2010-08-13 17:42:45.489 RetainRelease[20933:a0f] NSString - retain count=1
2010-08-13 17:42:45.491 RetainRelease[20933:a0f] NSString - retain count=1
答案:
it's implemented as "when the object is released with a retainCount of 1, it's deallocated", because there's no need to ever decrement it to 0. It's an implementation optimization.
分享到:
相关推荐
spring-boot-2.3.8.RELEAS Edemo
windows编译的geos库,版本:geos3.6.5 包含releas、debug版本
springloaded-1.2.4.RELEAS
leensa-1.0.4-foss-releas.apk
com.lingyue.zebraloan-v4.6.0-ZEBRA_CAMPAIGN-releas.apk
spring-roo里面有打包,还有需要的东西,这是release版本
Oracle Solaris 8 Solaris 8 (Intel Platform Edition) 1/ 01 Release Notes Update-92
Oracle Common Application Components Implementation Guide Release 11i Part No. B12394-01
Oracle Marketing Encyclopedia System Implementation Guide Release 11
Oracle Applications Desktop Integrator Installation Guide Release 7.2 for Windows
Oracle R Enterprise Installation and Administration Guide Release 1.3.1 for Windows, Linux, Solaris, and AIX-96
Oracle Financial Analyzer Installation and Upgrade Guide Release 11
Oracle Database Installation and Administration Guide 11g Release 2 (11.2) for Fujitsu BS2000/OSD-156
Oracle TimesTen In-Memory Database Installation Guide 11g Release 2 (11.2.2)-120
Oracle8i Application Developer’s Guide - Advanced Queuing Release 2 (8.1.6)
Oracle Database Real Application Testing User’s Guide 11g Release 2 (11.2)-250
spring框架中的data-commonsjar资源包
Oracle Solaris 8 Solaris 8 (SPARC Platform Edition) 10/00 Release Notes Update-80