0

For example, if I moved from activity1 to activity2, how can I release device memory from this first class? E.g. using ComponentsCallback2

User656
  • 21
  • 4
  • Why not just call `finish()` in `activity1` after starting `activity2`? – TheWanderer Sep 14 '18 at 14:46
  • Oh, It's true :) – User656 Sep 14 '18 at 14:50
  • you can kill a specific object by overriding the onDestroy method – Bayar Şahintekin Sep 14 '18 at 14:57
  • 2
    @BayarŞahintekin No you can't. That's not how garbage collection works – Gabe Sechan Sep 14 '18 at 15:01
  • If the first Activity was destroyed, (say via finish) it will be freed for you assuming you don't have a leak or another reference to it. If it wasn't, when you run low on memory Android will destroy it for you (sam assumptions). If you do have a memory leak, you need to fix that and it will get properly freed. – Gabe Sechan Sep 14 '18 at 15:04
  • Sometimes manual intervention may be required. I use it to prevent data leakage in my work. mine was just an idea. @GabeSechan – Bayar Şahintekin Sep 14 '18 at 15:05
  • If you wish to know if you have memory leak issues, I highly recommend you use `LeakCanary` from Square - https://github.com/square/leakcanary By the way, I recommend you improve your question with some information as to why you think you need to do this. Is Activity1 using too much memory and not releasing upon `onDestroy()`? – Dayan Sep 14 '18 at 15:08
  • @BayarŞahintekin Sometimes that's part of an answer (like if you need to unregister things to remove references outside of the Activity). But just overriding onDestroy without a specific reason isn't going to do anything- especially if the Activity isn't destroyed. – Gabe Sechan Sep 14 '18 at 15:08

0 Answers0