美文网首页
Find abandoned memory

Find abandoned memory

作者: Suffic | 来源:发表于2018-01-14 19:16 被阅读0次

The Allocations profiling template uses the Allocations and VM Tracker instruments to measure general and virtual memory usage in your app. However, to track down abandoned memory that’s been allocated but isn’t needed again, focus strictly on the Allocations instrument. This instrument measures heap memory usage and tracks allocations, including specific object allocations by class.

Launch Instruments.

In the profiling template selection dialog that appears, click Allocations.

Choose your device and app from the target device and process lists.

Click Choose to create a trace document.

Click the Allocations instrument in the timeline pane.

The Mark Generations button appears in the filter and configuration bar at the bottom of the detail pane.

Click the Record button () in the toolbar (or press Command-R) to begin recording.

Perform a short sequence of repeatable actions in your app.

In order to accurately generate trends, this should be a set of actions that starts and finishes with the app in the same state.

Click the Mark Generation button in the filter and configuration bar.

A flag appears in the track pane to identify the generation.

A list of generations you’ve marked is shown in the detail pane. Each generation includes a list of allocations that has occurred since the previous generation.

You can also mark generations after you’re done recording by dragging the inspection head in the track pane’s timeline to the desired location and clicking Mark Generation.

Perform steps 8 and 9 several times while monitoring the detail pane until you see whether memory is growing without limit.

Important: During the first few iterations, extra allocations may occur due to caching. Therefore, it is important to create a few initial generations for the purpose of establishing a baseline. Then, create additional generations for true analysis.

Click the Stop button () in the toolbar (or press Command-R again) when you’re ready to stop recording.

Scan through the generations in the detail pane and find one that seems representative of repeated memory growth.

The Growth and # Persistent columns tell you how much additional memory and how many allocations have occurred since the previous generation. If your app returns to its original state after an operation, you shouldn’t expect there to be growth from generation to generation.

Click the disclosure triangle () of a generation to display new objects that have been allocated since the prior generation.

Look for objects that are persisting. If you identify one, click the disclosure triangle () to display its instances.

Select an object instance.

Press Command-3 to display a stack trace for the selected instance in the extended detail area of the inspector.

This stack trace provides the complete list of method calls responsible allocating the instance.

Click the Collapse button () in the extended detail area to hide system calls in the stack trace. This makes it easier to locate your app’s methods.

Calls made by your app are colored black and preceded by a user code icon ().

Control-click on an entry in the detail pane, in the popover that appears choose Reveal in Xcode to show the source in Xcode.

Screenshot showing the popover for opening the user symbol in Xcode

Determine whether the allocation is useful. If it’s not, it’s abandoned memory that needs to be resolved.

Because abandoned memory is still referenced by your app, Instruments can’t determine its importance. To find abandoned memory, use generational analysis to ensure that memory does not continue to grow while repeatedly performing the same set of operations. For example, ending and starting a new game, opening and closing a window, creating and deleting a contact, or setting and unsetting a preference are all operations that should conceptually return your app to a previous and stable memory state. Extensive cycling through such operations many times should not result in unexpected or unrestrained memory growth. Instruments helps you correlate periods of memory growth with specific object allocations, so you can release them and reduce your app’s memory footprint.

相关文章

  • Find abandoned memory

    The Allocations profiling template uses the Allocations a...

  • 性能优化

    一,内存泄露检测Leaked memory(内存泄漏) 和 Abandoned memory(内存无限增长) 都属...

  • 猜猜这是什么歌?

    (不知道今天单曲循环了多少遍!!!) Mom, they abandoned me, abandoned me j...

  • Spiral Memory;Simple Number Find

    导航:jupyter notebook

  • Find out biggest cpu/memory cons

    Biggest memory consuming processes Biggest cpu consuming ...

  • A-abandoned

    这个时代,每个人都害怕被丢下。不焦虑的人,要么是领跑的,要么是意识不到自己已经被丢下了。 小A就是每天奔跑在路上的...

  • abandoned,then abandon

    不管是听歌,还是人生。 就那么一阵子一阵子的。 抽疯。 有那么一阵子,我就喜欢听这种暗黑系,很丧,又很野的。 同时...

  • CUC-SUMMER-1-K

    K - An abandoned sentiment from past CodeForces - 814A A ...

  • Garden

    Several stories have mentioned an abandoned ancient garde...

  • To The Lost Memories

    If you noticed somethings were abandoned by chance, pleas...

网友评论

      本文标题:Find abandoned memory

      本文链接:https://www.haomeiwen.com/subject/mchloxtx.html