简体   繁体   中英

ReactiveCocoa: RAC Objects still in memory after all signals complete

I am developing an application on iOS8 based on reactive cocoa. The application mainly does network operations.

I noticed that when all my signals complete and all signal references are nulled, i see a few RAC* objects still alive in the memory when i checked through instruments. Is this intended or is my code leaking memory? When i run the signal, there is an activity surge where i see a lot of RAC objects getting allocated and then it falls back to this state as shown the the below screen capture.

Every subsequent invocation ends in this same state. So i am not very worried about it btw.

http://imgur.com/sCL8Y3p

Thanks,

Those are all shared global instances that RAC uses so it doesn't need to allocate memory for every use of them. I'm sure there's a fancier word for that optimization, but I can't think what it is. For example, check out RACUnit :

+ (RACUnit *)defaultUnit {
    static dispatch_once_t onceToken;
    static RACUnit *defaultUnit = nil;
    dispatch_once(&onceToken, ^{
      defaultUnit = [[self alloc] init];
    });

    return defaultUnit;
}

Since all RACUnit s are the same, RAC never bothers to make more than one instance of it. That's all you're seeing.

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