mutableBytes Creates Autoreleased Objects
mutableBytes Creates Autoreleased Objects
- Subject: mutableBytes Creates Autoreleased Objects
- From: Andreas Grosam <email@hidden>
- Date: Sat, 12 May 2012 17:27:32 +0200
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 (email@hidden)
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:
This email sent to email@hidden