java - 内存使用率高且同一进程显示多次?

标签 java android memory-management android-mediaplayer

我在 Android Studio 中制作了一个媒体播放器,它使用服务来控制播放。

现在一切正常,即使我的 logcat 说启动期间跳过了 123 帧,我也没有注意到任何延迟。

我在某处读到,如果这条消息不超过跳过 300+ 帧,则可以忽略该消息,但现在我不再那么确定了,因为我现在读到即使跳过 1 帧也太少了很多。

我还将 RAM 使用情况与商店中的 mp3 播放器进行了比较,我注意到大多数媒体播放器的内存使用情况都低于 10mb。

但我的超过了近50mb,我不知道为什么,但如果你查看详细信息,你可以看到有相同名称的进程和很多“sandboxed_processes” .

所以我的问题是我的应用程序几乎消耗 50mb 内存是否可以,以及那些“sandboxed_processes”的含义。

enter image description here

最佳答案

问题 1:

这取决于您的应用程序正在使用和需要多少资源。您应该认真对待内存,并且应该使用尽可能少的资源。垃圾收集器将帮助您回收分配的内存,但您应该考虑您创建的任何对象实例的生命周期,以及它们的设计,以便最大限度地减少结构。最后但并非最不重要的一点是,Studio 允许您分析应用程序的内存分配,因此请使用它:)。

问题 2:

应用沙箱来自官方documentation

The Android platform takes advantage of the Linux user-based protection to identify and isolate app resources. This isolates apps from each other and protects apps and the system from malicious apps. To do this, Android assigns a unique user ID (UID) to each Android application and runs it in its own process.

Android uses this UID to set up a kernel-level Application Sandbox. The kernel enforces security between apps and the system at the process level through standard Linux facilities, such as user and group IDs that are assigned to apps. By default, apps can't interact with each other and have limited access to the operating system. For example, if application A tries to do something malicious, such as read application B's data or dial the phone without permission (which is a separate application), then the operating system protects against this behavior because application A does not have the appropriate user privileges. The sandbox is simple, auditable, and based on decades-old UNIX-style user separation of processes and file permissions.

Because the Application Sandbox is in the kernel, this security model extends to native code and to operating system applications. All of the software above the kernel, such as operating system libraries, application framework, application runtime, and all applications, run within the Application Sandbox. On some platforms, developers are constrained to a specific development framework, set of APIs, or language in order to enforce security. On Android, there are no restrictions on how an application can be written that are required to enforce security; in this respect, native code is as sandboxed as interpreted code.

关于java - 内存使用率高且同一进程显示多次?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56352462/

相关文章:

android - 消息处理程序和 WeakReference 问题

android 将操作栏更改为工具栏

C - 内存泄漏故障排除

c++ - push_back() 是否总是增加 vector 的大小?

c++ - 比较使用不同分配器的 STL 字符串

java - Spring Data JPA - 实体名称无效标识符

java - 在 Seam 的 Java 类中使用消息包

java - 在 Eclipse Helios 中安装 Android SDK 的问题

JAVA/JAXB 需要帮助

java - Android:将一些只读字节传递给 native C++ 的最有效方法