为什么在android时自动释放了这段内存?

Why automatically released this memory at android?

我的 android appwiget 有一些内存问题, (这是基于小玩具 appwidget 的可绘制动画重复)

所以我在 Android Studio 中观看了我的内存查看器。

我发现我的应用程序的内存在初始时间增加了,但是当它没有足够的内存时它会自动释放一些内存。

  1. 我想知道 android 是什么函数做的。

  2. 我可以用java代码控制这个释放功能吗?

*我在真机上测试过 android ver 4.42

你说的是Garbage Collection, which is the process of removing from the memory the objects that are no longer required. You can have a good idea of how it works in Java here

在 Android(通常是 Java)中,您可以 建议 虚拟机通过 System.gc() 调用来完成它。不过请注意,它:

Indicates to the VM that it would be a good time to run the garbage collector. Note that this is a hint only. There is no guarantee that the garbage collector will actually be run.