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

Inefficient use of heap causes frequent gc #367

Open
Nik-Gleb opened this issue Dec 15, 2016 · 4 comments
Open

Inefficient use of heap causes frequent gc #367

Nik-Gleb opened this issue Dec 15, 2016 · 4 comments
Milestone

Comments

@Nik-Gleb
Copy link

Nik-Gleb commented Dec 15, 2016

I like this library, thanks to the authors for their labor ;)
And sorry for my bad english.

In my project i have a grid of gif's (about 4x5, may be less) and today I was faced with frequent "gc-calls", and ever-growing using-heap. I discovered an issue in draw-method of gif-drawable.
mRenderTaskSchedule = mExecutor.schedule(mRenderTask, renderDelay, TimeUnit.MILLISECONDS);
Unfortunaly, java's native ScheduledThreadPoolExexcutor.schedule creates new objects, wrappers,...etc ever call

I think it makes sense to make the mRenderTaskSchedule reusable, or create any EfficientScheduledExecutor implementation, via reflections, may be jni reflections or other workarounds

Thanks.

@koral--
Copy link
Owner

koral-- commented Dec 16, 2016

Indeed, ScheduledThreadPoolExecutor#schedule() causes allocations.
Some classes from this library eg. GifTexImage2D use native (pthread) threads to change GIF frames.
It should be possible to use that mechanism also in GifDrawable. I'll check this.

@Nik-Gleb
Copy link
Author

Nik-Gleb commented Dec 16, 2016

Ok. Perhaps it (pthread) will be more cleanest solution. Thanks.

@koral-- koral-- added this to the 2.x milestone Jan 22, 2017
@koral--
Copy link
Owner

koral-- commented Jan 22, 2017

Assuming that each GifDrawable will spawn its own thread. It seems that it should be additional option, not replacement of current behavior.
Adding 2.x milestone for this issue.

@Nik-Gleb
Copy link
Author

Nik-Gleb commented Jun 1, 2017

Hi!

You can also use the Handler-based approach, to schedule decode operations.
Android already knows how to do it correctly and there is a message pool for more efficient memory using.

I think, the drawable can be free from liability by threads-managing.
The user can provide his own looper for decoding operations,
else - the MainLopper will be used by default.
mHandler = new Handler(looper);

You are also not required to return to the main thread explicitly:
scr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants