Logo Questions Linux Laravel Mysql Ubuntu Git Menu

joda time consume too much memory

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!

like image 484
Vigor Avatar asked Mar 24 '23 03:03


2 Answers

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.

like image 139
Michael J. Lee Avatar answered Apr 05 '23 21:04

Michael J. Lee

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.

like image 44
Vigor Avatar answered Apr 05 '23 20:04