I was wondering if it is possible to tweak the way garbage collector works on JavaMe in order to improve performance somehow(may reducing the number of passages)? I´ve seen some articles about it, but mostly directed Java SE and most of them says GC is highly dependant on the maker. How much would that be.
相关问题
- C# GC not freeing memory [duplicate]
- Faster loop: foreach vs some (performance of jsper
- Why wrapping a function into a lambda potentially
- garbage collection best practices
- Ado.net performance:What does SNIReadSync do?
相关文章
- DOM penalty of using html attributes
- Which is faster, pointer access or reference acces
- Django is sooo slow? errno 32 broken pipe? dcramer
- Understanding the difference between Collection.is
- parallelizing matrix multiplication through thread
- How to determine JS bottlenecks in React Native co
- Difference between SuspendLayout and BeginUpdate
- Efficient Rolling Max and Min Window
Thanks for all the input people. I´ve seen it´s not possible to tweak the GC for Java Me capable devices. At least not in any easy or usefull way. I´ll leave this question open anyway, in case this scenario changes somehow in the time being. :)
I don't see any possible way to tweak the garbage collection behavior in J2ME.
If you have problems with pauses induced by garbage collections, you have to do two things:
When the garbage collector is triggered is largely a mistery unless you have first hand knowledge of how the particular VM your application is running on was implemented and exactly how it was configured and customized for the specific phone you are using.
Calling java.lang.System.gc() is no guarantee that the garbage collector is triggered. It usually merely increases the probablility of the VM launching garbage collection very soon.
I have found that calling System.gc() 3 times consecutively in the same Thread but from 3 different methods tends to work reasonably well.
There are many ways to work around ineficiencies in the JavaME standard API implementations in order to reduce the amount of garbage you generate:
Extend ByteArrayOutputStream so you don't create a copy of the byte array when you want to access the data.
avoid calling StringBuffer.getChars() and StringBuffer.toString(). make your code work with StringBuffer offsets and lengths instead.
turn local buffers (byte[], StringBuffer...) into instance or static variables (and protect them with synchronized). Obviously, there is an overhead to doing this but it can prevent your application from freezing due to garbage collection too often.
Extend StringBuffer to avoid switching back and forth between String and StringBuffer : implement append(String, offset, length), parseInt(int), indexOf(String, index), replace(offset, StringBuffer, offset, length)...
...