It seems, sending mutableBytes creates autoreleased objects (currently, tested 
with ARC only).
Anybody experienced this, too?

In code as below this may severely impact performance and tie up lots of 
memory, which are apparently dependent on the size of the mutable data:

for (int i = 0; i < BigValue; ++i) {
    NSMutableData* data = [[NSMutableData alloc] initWithCapacity:bigSize];
    char* p = [data mutableBytes];
    ...

    // data released by ARC
}

I could alleviate the problem by wrapping around an autorelease pool:


for (int i = 0; i < BigValue; ++i) 
{
    NSMutableData* data = [[NSMutableData alloc] initWithCapacity:bigSize];
    char* p;
    @autoreleasepool {
        char* p = [data mutableBytes];
     }
    ...
}

(In practice, it would probably be more kosher to wrap the whole block within 
the loop. I did it so just to illustrate where the autoreleased objects will be 
created.)


Honestly, that seems quite strange.
I also would expect this to be mentioned in the docs.


Regards
Andreas
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to