Fix a memory leak.

This commit is contained in:
B. Petersen
2017-01-11 00:09:50 +01:00
parent 6d3c170e96
commit 848862ae84
2 changed files with 9 additions and 4 deletions
@@ -177,7 +177,6 @@ public class ContactsController {
//ContactsContract.CommonDataKinds.Email.DISPLAY_NAME,
};
private static final Object s_sync = new Object();
private static HashMap<View, String> s_viewBindings = new HashMap<>();
private static HashMap<String, AvtCacheEntry> s_avtCache = new HashMap<>();
public static void cleanupAvatarCache() {
@@ -235,7 +234,7 @@ public class ContactsController {
// moreover, check if the avatar is in cache
AvtCacheEntry cacheEntry;
synchronized (s_sync) {
s_viewBindings.put(avtView, email+fallbackName);
avtImageReceiver.m_userDataUnique = email+fallbackName;
cacheEntry = s_avtCache.get(email+fallbackName);
}
@@ -264,7 +263,7 @@ public class ContactsController {
public void run() {
// is the avatar still desired?
synchronized (s_sync) {
if (!s_viewBindings.get(avtView).equals(email+fallbackName)) {
if (!avtImageReceiver.m_userDataUnique.equals(email+fallbackName)) {
return;
}
}
@@ -307,7 +306,7 @@ public class ContactsController {
public void run() {
// is the avatar still desired?
synchronized (s_sync) {
if (!s_viewBindings.get(avtView).equals(email+fallbackName)) {
if (!avtImageReceiver.m_userDataUnique.equals(email+fallbackName)) {
return;
}
}
@@ -43,6 +43,7 @@ import com.b44t.ui.Components.AnimatedFileDrawable;
public class ImageReceiver implements NotificationCenter.NotificationCenterDelegate {
public interface ImageReceiverDelegate {
void didSetImage(ImageReceiver imageReceiver, boolean set, boolean thumb);
}
@@ -59,6 +60,11 @@ public class ImageReceiver implements NotificationCenter.NotificationCenterDeleg
public String ext;
}
public String m_userDataUnique = ""; // used to discard images loaded and no longer required as there was a new request
// before, we used "private static HashMap<View, String> s_viewBindings = new HashMap<>();" in ContactsController -
// however, this was a bad idea as this resulted in _lots_ of objects that were never freed...
private View parentView;
private Integer tag;
private Integer thumbTag;