Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory keeps rising without getting memory leak notification from leakcanary

I am new to android Profiler and still a noob at memory management. At first, I am having a notifications from LeakCanary so I fix them and successfully removed the leakage so the LeakCanary stops sending me notifications. But when I use the android Profiler I just noticed that the memory usage was rising bit by bit when I open a certain activity and then destroy it using finish(); method. Below are the sample screenshots of my Profiler when I open and close the OrdersActivity.

Here is the SS of total memory used before opening and closing the OrdersActivity enter image description here

And here is the SS of total memory used after opening and closing the OrdersActivity enter image description here

Also here is the stacktrace of the LeakCanary enter image description here

I want to know if this occurrence of rising memory is normal? If not, is there a way to stop this? I am willing to show my codes If you need them in order to help me. I just didn't include it because it was too long.

like image 615
Mr. Baks Avatar asked Dec 28 '25 04:12

Mr. Baks


1 Answers

LeakCanary will detect memory leaks, in the sense of objects that remain in memory when the activity is closed.

If you want to understand why memory usage is increasing as an activity is running, you can track allocations using the profile.

Edit: Also, it's hard to read a screenshot, but it seems to me that was is increasing when you start the activity is code (Code: Memory that your app uses for code and resources, such as dex bytecode, optimized or compiled dex code, .so libraries, and fonts.). In that case, that's perfectly normal: starting an activity need to load extra code (the activity itself, which is probably small, and all of required AppCompat if it hasn't been loaded yet). The usual strategy to test against memory leaks is to start and close the activity hundred times, and verify there is no memory increase between the 2nd time and the 100th time.

like image 147
rds Avatar answered Dec 30 '25 18:12

rds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!