简体   繁体   中英

reinitialize/reallocate an object with ARC

Im wondering if calling [[MyClass alloc] init] on an already existing (allocated) object create a leak in ARC? or does it manage the release and reallocation for you?

would doing the following be more proper:

myObject = nil;
myObject = [[MyClass alloc] init];

which is more appropriate? is there another way to do this properly?

With ARC, you don't need to set the myObject to be nil before reallocating it,only this line of code will be fine:

myObject = [[MyClass alloc] init];

When xcode compiles the code, it will automatically add the right release mechanism in.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM