7 ms·
It was pretty ridiculous, even on some of the most powerful hardware out there I still found animations to lag from time to time due to the GC_FOR_ALLOC calls!
by rohan404 12y ago
It was pretty ridiculous, even on some of the most powerful hardware out there I still found animations to lag from time to time due to the GC_FOR_ALLOC calls! Ended up with a bunch of hacks to try to work around the issue, but none fully resolved it.
- on_and_off 12y agoIf animations lag because of allocations, then you are allocating too many objects.. The most common cause is object allocation in a critical part like a draw call (or view binding).
- rohan404 12y agoThis is true, but for operations like loading images from disk for example, this is unavoidable. The best you can do is reuse memory instead of allocating whenever possible
- kuschku 12y agoOn Android you should definitely load the images Async and not load them within the draw call.
- rohan404 12y agoEven loaded asynchronously, the calls for allocation still cause lag. Unless I am doing something incorrectly?
- on_and_off 12y agoYou can use inBitmap in order to reuse bitmap instances instead of of allocating new objects. If it fits your use-case, Glide is a very modular lib that implements inBitmap. It is true that you will always have to create some objects though. For example with Glide, a DataFetcher is created with each new image request. You should do your best to keep it at a minimum though, with a focus on creating heavy objects only when it is absolutely necessary. Other than that, lag can come from many things, so if you lag without GC, the only solution is to profile that part of your app.
- izacus 12y agoNo matter what language, allocations are expensive. Your stuttering would appear in C++, ObjC or Java. Don't mistake slow allocations for a GC issue.