2

65MB seems like an extremely high amount of memory usage for an app that only displays "Hello World" on the screen. To be clear, all I did was create a default empty activity project in Android Studio and build it -- I haven't added or changed anything in the project. Is this normal? I'm using Android Studio Electric Eel 2022.1.1 Patch 2.

Paul Slocum
  • 1,454
  • 13
  • 18
  • The project is not so empty as you think. The default projects make use of androidx compatibility libraries which allows to develop apps without having to manually consider all the different Android versions. So your app contains a thick compatibility layer which can also be seen in the APK size of 1MB+. – Robert Apr 20 '23 at 07:58
  • I'm talking about RAM usage in the profiler, not APK size. – Paul Slocum Apr 20 '23 at 11:46
  • Both are not the same but related. An app having a lot of classes in it's APK that are loaded at runtime of course has a bigger RAM footprint. – Robert Apr 20 '23 at 12:01
  • 2
    When I create an "Empty Activity" (min SDK 30)project and run it on Android 12 (debug build) the RAM usage is 76MB. Clicking on the diagram reveals that a very large parts are 23MB code and 22MB was for graphics. If the app is in background this reduces to 4MB. BTW. Please check the created APK, it is ~16MB containing android support, androidx and kotlin libraries. – Robert Apr 20 '23 at 12:14
  • Thanks for confirming the high memory usage on new projects. The APK for my build is only 2.8MB, so that doesn't explain the high memory usage. – Paul Slocum Apr 20 '23 at 12:37

1 Answers1

1

After a lot of research and others confirming that a newly created Android Studio project uses a lot of memory, I've concluded that this is simply normal for Android, and that Android and Java are just very inefficient memory-wise for small applications. Android apparently loads a lot of libraries and starts multiple memory-hungry threads even if you application barely does anything.

Some of the 65MB memory usage was caused by the fact that I was using a debug build, but switching to a release build still uses almost 45MB, whereas a "Hello World" application on iOS only uses 2MB.

Some people claimed that some of that memory was pre-allocated for my program to use, but I found that if I loaded a library that I expected to use about 40MB, then the total usage climbed from 65MB to over 100MB. So the idea that it is preallocating memory for my program does not seem to be the case.

The best general answer I found to this question is here: https://stackoverflow.com/a/17403555/408877

Paul Slocum
  • 1,454
  • 13
  • 18