Is it a memory leak in android

user1979221

I have created simple app with two acitivities, in both activities there a button which links to another activity.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.two);
    Button btn = (Button) findViewById(R.id.button);
    btn.setOnClickListener(this);
}

@Override
public void onClick(View view) {
    if (intent != null) intent = null;
    intent = new Intent(Two.this,MainActivity.class);
    startActivity(intent);
}

In both activity there is same code. When i press Button and press Cause GC in DDMS, allocated is always growing by 25kb is it normal?

Gergely Kőrössy

I wouldn't call it a memory leak but poor concept. What you are doing is putting activities on the stack which, of course, takes up more and more memory. If you want to just open the previous activity (thus not creating a new one each time you call startActivity(...)), use this:

Intent intent = new Intent(Two.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

If you want to know more about tasks and the back stack, visit this guide.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Android animations memory leak

From Dev

Is it a memory leak in android

From Dev

memory leak with Android WebView

From Dev

Android - is this a memory leak?

From Dev

Prevent memory leak in Android

From Dev

Android inner classes memory leak and leak by context?

From Dev

Android - Device Memory Leak with Fragments

From Dev

Android Fragment Webview Memory Leak

From Dev

Android runOnUiThread causing memory leak

From Dev

Android camera Bitmap memory leak

From Dev

Android progress bar memory leak

From Dev

`Unknown` (`Other`) memory leak in Android?

From Dev

Android runOnUiThread causing memory leak

From Dev

Getting Memory leak on android fragment

From Dev

Android memory leak Custom view

From Dev

Android memory leak on device, not on emulator

From Dev

Android Memory Leak - Anonymous class

From Dev

Avoid memory leak with WeakReference Android

From Dev

How to release memory in android to avoid memory leak

From Dev

Android memory leak on textview - LeakCanary (Leak can be ignored)

From Dev

Android Does my app have a memory leak?

From Dev

Memory leak with GoogleApiClient detected by Android Studio

From Dev

Memory leak due to android.widget.BubblePopupHelper

From Dev

Memory leak in very simple Android App

From Dev

Android VideoView Http Live Streaming Memory Leak

From Dev

Android memory leak on static Resource member variable?

From Dev

Android Socket - Memory Leak - Incoming message

From Dev

Delphi Android Memory Leak(or another slowdown)

From Dev

Android VideoView Http Live Streaming Memory Leak