1

I'm working on my first android application which is a big application though.. I have completed half of my app but what makes me worry is that the memory used by app.. Initially I faced the issues regarding out of memory exceptions.. I first started analyzing my app with MAT(Memory Analyzer Tool) of Android Studio, which was very difficult to track the memory usage.. My app would reach allocated space of 96mb and crash.. Then After Reading on internet i used Leak Canary which pointed out the static resources that was eating memory.. and now my app regularly gets Garbage collected but still i find the allocated space remains to be around 70 mb, Like my app starts with allocation of 30mb when i use app for about 2 min and come back to initial screen the allocated space is not same as initial... For beginners like me it is hard to track the memory usage to the core using MAT and is there a best approach or tool which would give me a clear picture of allocated space by objects.. Objects that are taking maximum space.. objects that are supposed get destroyed but not destroyed?? and retaining Image memory etc etc Thanks in advance

4

2 回答 2

1

主要的“内存泄漏者”之一是位图。有时,当您在视图中加载图像时,它会在操作中使用大量内存。我曾经推荐使用 Glide 或 Fresco 之类的库,它们可以更好地处理内存问题并且已经实现了许多通用功能。

您也可以尝试在 onDestroy 方法中为每个活动释放资源。

不过,如果您能给我们更深入地了解您的项目,我会很好。

问候。

于 2016-07-29T13:23:35.480 回答
0

这里有一些与内存管理相关的帖子。

我们在某些时候都是新手,谢天谢地,这些经验和问题已被证明是优秀的“老师”。
就像我在另一篇文章中所说:

这当然会导致内存问题,例如泄漏、OOM 和不必要的资源绑定。绝对没有自动释放内存的方法。在任何情况下,您都不能完全依赖垃圾收集器

基本上,您必须确保只分配所需的资源,并在您知道在 Lifecyce 中不再需要它们时立即释放它们

我用代码(你可以在你的项目中实现)写了一个更详细的解释来处理你的内存问题,可以在这里找到:

在这里能找到它

问候,

于 2016-07-29T14:21:44.213 回答