Siri
Siri

Reputation: 701

Android application on low memory calling

In my application i override the onLowmemory method. It gets called every time. And my mobile is stuck. How to release memory in this method.

I am using below code :

@Override
    public void onLowMemory() {
        // TODO Auto-generated method stub
        super.onLowMemory();
        System.out.println("*************************************************");
        System.out.println("********** on low memory ************************");
        System.out.println("*************************************************");
        System.gc();
    }

Only using system.gc ... thank you.

Upvotes: 0

Views: 1261

Answers (2)

Master
Master

Reputation: 683

I don't know what's going on, but my application stopped killing lowMemoryKiller when I added this code:

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        Runtime.getRuntime().gc();
    }

Upvotes: 0

RocketRandom
RocketRandom

Reputation: 1122

You should never call System.gc() it creates performance issues. You have to free references to any heavy objects you are holding - Look at the footprint of your application. Take a heap dump and see it in MAT. Look at what objects are taking most memory and check if you can free them.

Upvotes: 1

Related Questions