Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to trace memory consumption of an iOS app?


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Sep 4, 2015 3:17 AM Last Post By: Hans Jakobsen
Hans Jakobsen

Posts: 103
Registered: 9/10/01
How to trace memory consumption of an iOS app?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2015 8:36 AM
With XE8upd1, I get the TApplicationEvent.LowMemory quite often, even on an iPad with 1 GB memory.

Using X-code Instruments, I get this, just by running my application until it shows its first screen:
"All heap & Anonymous VM": Persistent Bytes: 199 MB, Transient Bytes: 635 MB, Total 834 MB

834 MB allocated is a lot... expanding the list of allocations reveals a list of 187.000 memory allocations!
Trying to solve this, I have a few questions:

1) What is "Transient Bytes"? - I have not been able to Google a clear answer to that

2) About 90% of the 187.000 allocations show only the text "Malloc x bytes" (where x is anything from a few bytes to many MB). How do I find out what parts of my code caused each of them to be allocated?

3) What is the best approach in general to trace iOS memory consumption?

Note: The iOS application has quite a lot of independent code as the GUI is made with TMS iCL native components and we have developed a lot of native code using CoreMidi, AudioToolbox, AudioUnit, etc.
The same application targeting Windows, is only 230 MB according to Task Manager, so traditional memory tools for Windows will only be useful for reducing that part.

Best regards,
Hans

Sebastian Zierer

Posts: 182
Registered: 4/3/00
Re: How to trace memory consumption of an iOS app?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 31, 2015 1:07 PM   in response to: Hans Jakobsen in response to: Hans Jakobsen
Hans Jakobsen wrote:
2) About 90% of the 187.000 allocations show only the text "Malloc x bytes" (where x is anything from a few bytes to many MB). How do I find out what parts of my code caused each of them to be allocated?
3) What is the best approach in general to trace iOS memory consumption?

Take a look at the Malloc Debugging Features:
https://developer.apple.com/library/prerelease/ios/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html

I haven't tried this for iOS yet, but you could also try setting a breakpoint in the malloc function, possibly with a condition of the memory size that is allocated.

Keep in mind that ARC in Delphi for iOS does not manage memory that is allocated by Cocoa or the system libraries. You will have take care of that. Whenever you create a Cocoa object, you must also call its release function. Delphi only releases the wrapper for you, not the underlying object.

-Sebastian
Hans Jakobsen

Posts: 103
Registered: 9/10/01
Re: How to trace memory consumption of an iOS app?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 4, 2015 3:17 AM   in response to: Sebastian Zierer in response to: Sebastian Zierer

It looks like they are useful to trace memory errors?

For #1, What I have found is that the Transient bytes are bytes that have been allocated but are released again. Therefore they are probably not causing the LowMemory message to appear.

To trace memory consumption, I have done something else. I translated a function from Objective-C that returns the current use of memory for the application. This is useful to find how much the memory allocation grows when running and creating various sections of my code. I have included it here:

http://stackoverflow.com/questions/32351687/converting-objective-c-code-to-delphi-xe8
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02