nonopolarity
nonopolarity

Reputation: 151196

Is there a way to see the maximum memory use of an iOS app since it started up?

If there is an app and we started it up, we can use Instruments to look at the memory usage second by second, but what if during initialization, the memory shot up to 60MB for a split second, and then come back down? (such as a few large graphics contexts and bitmaps and CALayers).

Is there a way to see the maximum since the app started up? I thought of a caveman way, which is to add a dummy loop of, say a million or 10 million, after we have allocated the large graphics context and bitmaps and CALayers, so that the memory use is constant for a few seconds, and can be seen in Instruments.

But then it should be better that if there are 5 layers, we should allocate one graphics context, get the bitmap, and set it to the layer, and immediately release the graphics context since it is not needed any more. And then we go on to the next graphics context, bitmap, and layer, and so on, instead of creating five graphics contexts, bitmaps, and release all five at the end. But to do the cavemen method, we need to add the dummy loop to all five places before each release. Is there a better way to do it?

Upvotes: 3

Views: 152

Answers (1)

Swift Dev Journal
Swift Dev Journal

Reputation: 20088

Use the Leaks or Allocations template and select the Allocations instrument. There is a graph next to the Allocations instrument. Click the timeline above the graph and hold the mouse button down. When you drag along the timeline, Instruments will show you the total amount of memory allocated at that point of time.

The difference between the Leaks and Allocations templates is the Leaks template sets the Allocations instrument to track all allocations while the Allocations template sets the Allocations instrument to track only active allocations.

Upvotes: 2

Related Questions