I want to figure out whether the Context object of one activity is being leaked to another activity. Does the following code leak the context of one activity to another?
Intent intent = new Intent(context, Demo.class);
context.startActivity(intent);
I want to figure out whether the Context object of one activity is being leaked to another activity. Does the following code leak the context of one activity to another?
Intent intent = new Intent(context, Demo.class);
context.startActivity(intent);
No, that doesn't "leak" your context. In general, to avoid leaking an Activity context, here's a few tips to follow:
ContextViews between ActivitysContext with an Activity reference, use the application's Context (context.getApplicationContext()).WeakReference when holding onto a Context while running some background operation (or whenever feasible really)As an addendum, use the Memory Analysis Tool (MAT) for eclipse to inspect a heap dump.