简体   繁体   中英

Property can retain an autoreleased object?

If I do this:

@property (nonatomic, retain) SomeObject* someInstance;

Why isn't someInstance still around even when I use an autorelease initializer on it?

For example:

someInstance=[SomeObject autoreleaseMethod];

I would expect someInstance to retain it in this case so you can use someInstance later, but is this not true?

Your property will only retain the object if you are using it's setter. In your example you forgot the self. :

self.someInstance = [SomeObject autoreleasedObject];

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