Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


If 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).


This 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


On Android you should definitely load the images Async and not load them within the draw call.


Even loaded asynchronously, the calls for allocation still cause lag. Unless I am doing something incorrectly?


You 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.


No matter what language, allocations are expensive. Your stuttering would appear in C++, ObjC or Java. Don't mistake slow allocations for a GC issue.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: