• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
mutableBytes Creates Autoreleased Objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: mutableBytes Creates Autoreleased Objects
      • From: Quincey Morris <email@hidden>
  • Prev by Date: Re: Accelerate framework
  • Next by Date: Re: mutableBytes Creates Autoreleased Objects
  • Previous by thread: Re: AwakeFromNib called twice for sheet
  • Next by thread: Re: mutableBytes Creates Autoreleased Objects
  • Index(es):
    • Date
    • Thread