How can I track down memory peaks? (That's peaks with a p, not an l.)

后端 未结 1 899
南旧
南旧 2021-01-11 17:22

I\'ve got a kiosk app, which, essentially shows a bunch of slides with various bits of information on them. I initially began coding this over a year ago, when I was beginni

相关标签:
1条回答
  • 2021-01-11 17:53

    What can I do to track down memory peaks? The memory is all being cleaned up by the application when it discards whatever it's using, but it doesn't seem to be discarding things.

    This is a classic case of "abandoned objects" or "usage accretion". That is, you have an application that, as it runs, builds up an object graph in memory as a normal part of usage. The objects aren't leaked because they are still connected to the live object graph. More likely than not, the objects are a part of either some kind of a cache (a write-only cache, most often) or a mechanism involving historical state (the undo stack is a potential source for accretion).

    To fix it, you need to make sure your object graph is pruned appropriately as your app runs. Caches should generally use a least-recently-used [LRU] pruning algorithm that limits the cache size. If a cache key ever goes invalid, that data should be pruned, too.

    For historical information, pruning the history is critical. So is making sure that the historical data contains an absolutely minimal representation of that historical state.

    Use Heapshot analysis -- it was created to help track down exactly these kinds of problems.

    I wrote a detailed "How to" guide; When is a Leak not a Leak?

    0 讨论(0)
提交回复
热议问题