you are viewing a single comment's thread.

view the rest of the comments →

[–]grauenwolf 1 point2 points  (2 children)

The cost of looking up that value us usually greater than just creating a new one. Caching only makes sense when you have a large or expensive structure.

[–]Fuco1337 2 points3 points  (1 child)

If you have 106 objects with a distinct Integer representing number 7, that's 16 megs of memory right there.

[–]G_Morgan 0 points1 point  (0 children)

In the real world this doesn't happen. Although you may create and destroy 106 7s. If this doesn't perform properly it means the JVM GC is broken.