Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cacheKeysForImageViews consumes a lot of memory #108

Closed
basileos opened this issue Nov 21, 2012 · 2 comments
Closed

cacheKeysForImageViews consumes a lot of memory #108

basileos opened this issue Nov 21, 2012 · 2 comments
Labels

Comments

@basileos
Copy link

Explain, please, what is the reason of using ImageViews as keys here:
private Map<ImageView, String> cacheKeysForImageViews = Collections.synchronizedMap(new WeakHashMap<ImageView, String>());
It causes memory leaks. I suppose:
private Map<Integer, String> cacheKeysForImageViews = Collections.synchronizedMap(new HashMap<Integer, String>());

And use imageView.hashCode() as key for this map. This fixes the issue for me.
But may be I miss something?

@nostra13
Copy link
Owner

cacheKeysForImageViews is used to detect if ImageView was reused to display another image (e.g. in ListView) and prevent loading and displaying previous image in reused ImageView.
Your solution with hashcodes is not bad but it will be terrible if hashcode collision happens.

Why did you decide cacheKeysForImageViews causes memory leaks?

@basileos
Copy link
Author

It works fine, while switching between different views and garbage collector does stuff, but I have view, which keeps many child views in cache, and in this case MAT shows cacheKeysForImageViews keys among main memory consumers.

nostra13 added a commit that referenced this issue Nov 27, 2012
Map key: ImageView -> ImageView.hashcode(). Remove map entry after
successful displaying.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants