Cocoa Memory Management NSArray with Objects

前端 未结 2 955
Happy的楠姐
Happy的楠姐 2021-01-26 01:58

I\'m having troubles releasing objects.. To explain it better I have included my code below.

NSTask *task = [NSTask new];
NSTask *grep = [NSTask new]; 
NSPipe *p         


        
2条回答
  •  野性不改
    2021-01-26 02:38

    substringToIndex: returns an autoreleased string, so there's no need to release it.

    The only memory leak I see is where you set up your 'pipe' var a second time (for the task's standard output) without first releasing its current value (the NSPipe instance used for standard error & input).

    Mutable collections like NSMutableArray will retain the objects they contain (as do all mutable/nonmutable collections) then release them when they're removed (or when the collection itself is deallocated).

提交回复
热议问题