0

I use NSMutableData class in my iOS program. I get unbounded memory growth. I use Automatic Reference Counting. When I used allocation instrument, I saw that NSMutableData's initWithLength: method having Malloc calls in order to allocate memory. Under ARC, memory that is allocated by using malloc should be released by the programmer because ARC doesn't do anything about it. Since I don't know the implementation of NSMutableData class, I can't be sure if the memory allocated by NSMutableData is released when NSMutableData is released. According to the allocations instrument, that's not the case. Does anyone have any knowledge on this?

Another question is when NSMutableData setLength: method is called with smaller size than the current size, then does the extra memory get released?

Amar
  • 13,202
  • 7
  • 53
  • 71
neo
  • 1,952
  • 2
  • 19
  • 39
  • "Since I don't know the implementation of `NSMutableData` class, I can't be sure if the memory allocated by `NSMutableData` is released when `NSMutableData` is released." The `NSMutableData` class is used so heavily that if it stopped cleaning up after itself one day, someone at Apple would get fired for letting such an enormous bug through. If you do not see `NSMutableData` release its internal data, then something is holding on to a reference to that `NSMutableData` object. – Sergey Kalinichenko Aug 12 '13 at 15:19
  • Do you think that I should put my code in between @autoreleasepool? – neo Aug 12 '13 at 15:31
  • Only if you repeatedly allocate/deallocate autoreleased objects in a loop. – Sergey Kalinichenko Aug 12 '13 at 15:32
  • 2
    @neo You would use `@autoreleasepool` to minimize the high water mark of an app (e.g. you have a loop that creates a lot of autorelease objects). But if you're not releasing the memory due to some strong reference, an `@autoreleasepool` won't help. – Rob Aug 12 '13 at 15:33
  • How do you know if an object is autoreleased object? – neo Aug 12 '13 at 15:44

0 Answers0