0
votes

I have a question regarding memory leaks. I have the below anonymous class. As you might know anonymous class hold reference from the outside object(here is Activity). Does this code causes memory leak or not? In case of orientation this will hold the old activity. Right?

Thank you

public class MainActivity extends AppCompatActivity{


recyclerview.post(new Runnable() {
@Override
public void run() {
    // Notify adapter with appropriate notify methods
    adapter.notifyItemRangeInserted(curSize, allContacts.size() - 1);
}
});

}
1

1 Answers

1
votes

Does this code causes memory leak or not?

Not really. That Runnable should be executed within a millisecond or so — otherwise, you have bigger issues.

If that Runnable would be around for an extended period of time, then you might have a memory leak.