This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void addTasks(List<Note> newNotes) { | |
NoteDiffUtil noteDiffUtil = new NoteDiffUtil(notes, newNotes); | |
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(noteDiffUtil); | |
notes.clear(); | |
notes.addAll(newNotes); | |
diffResult.dispatchUpdatesTo(this); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BroadcastReceiverLeakActivity extends AppCompatActivity { | |
private BroadcastReceiver broadcastReceiver; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_first); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class StaticReferenceLeakActivity extends AppCompatActivity { | |
/* | |
* This is a bad idea! | |
*/ | |
private static TextView textView; | |
private static Activity activity; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SingletonLeakExampleActivity extends AppCompatActivity { | |
private SingletonSampleClass singletonSampleClass; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
/* | |
* Option 1: Do not pass activity context to the Singleton class. Instead pass application Context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SingletonSampleClass { | |
private Context context; | |
private static SingletonSampleClass instance; | |
private SingletonSampleClass(Context context) { | |
this.context = context; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InnerClassReferenceLeakActivity extends AppCompatActivity { | |
/* | |
* Mistake Number 1: | |
* Never create a static variable of an inner class | |
* Fix I: | |
* private LeakyClass leakyClass; | |
*/ | |
private static LeakyClass leakyClass; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InnerClassReferenceLeakActivity extends AppCompatActivity { | |
/* | |
* Mistake Number 1: | |
* Never create a static variable of an inner class | |
* Fix I: | |
*/ | |
private LeakyClass leakyClass; | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AnonymousClassReferenceLeakActivity extends AppCompatActivity { | |
private TextView textView; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_first); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncTaskReferenceLeakActivity extends AppCompatActivity { | |
private TextView textView; | |
private BackgroundTask backgroundTask; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_first); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AsyncTaskReferenceLeakActivity extends AppCompatActivity { | |
private TextView textView; | |
private BackgroundTask backgroundTask; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_first); |