I use joda time in my code. When I add this line of code, the using memory will be increased 30M!
LocalDateTime _currDate = new LocalDateTime();
I found that nearly all the java programmers recommend to use joda time. so I think maybe I didn't use it in a right way. Anyone knows the reason, please help me. Thank you very much!
The JVM is pretty sophisticated and just because you instantiate a new object doesn't mean it will consume memory at that line of code. In some cases the JVM will never allocate memory to un-used objects EVEN if you explicitly instantiate them. You'll want to use a memory profiler to see what is exactly going on. Joda is a well built library and it's highly unlikely that this one class instantiation is causing your memory to increase by 30m.
A good profiler will show you how much memory that class is consuming, what's going on in the heap, along with several other useful insights. It could just be the JVM making more room on the heap to account for other things happening in your code.
I'm sure others will chime in on some good profilers but some IDE's will have them built right in. Start there and good luck.
I have found the reason of memory consuming for joda time. This is the answer: Android Java - Joda Date is slow according plowman's solution, I solved this problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With