Vigor
Vigor

Reputation: 1754

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!

Upvotes: 4

Views: 856

Answers (3)

Basil Bourque
Basil Bourque

Reputation: 338516

tl;dr

java.time supplants Joda-Time , with a back-port to Android.

java.time

The java.time framework is built into Java 8 and later. These classes supplant the old troublesome date-time classes such as java.util.Date, .Calendar, & java.text.SimpleDateFormat.

Now in maintenance mode, the Joda-Time project also advises migration to java.time.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations.

Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport and further adapted to Android in ThreeTenABP.

You may see a different memory usage profile with this library, though I have not tested it.

Upvotes: 0

Vigor
Vigor

Reputation: 1754

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.

Upvotes: 2

Michael J. Lee
Michael J. Lee

Reputation: 12406

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.

Upvotes: 5

Related Questions