Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

global vs local (variables and lists) by byte consumption JAVA

Tags:

java

I' trying to create a web site and some times I got the PermGen exception.
So I started searching for ways to reduce the amount of created objects and also to reduce the memory consumption.

I read some articles. But I'm not sure about some things.
For example, is it better to declare lists outside of a method (global), or to create them inside a method? What's the difference in terms of memory consumption in this case? If I declare them as local that means that after they are used the garbage collector will collect them and thus will release space at the heap?

Can anyone propose ways to reduce more memory consumption and to reduce the amount of created objects (is @Autowired a better way to declare on object)?

like image 712
Alex Dowining Avatar asked Mar 11 '26 20:03

Alex Dowining


1 Answers

If you are getting an Out-of-memory exception regarding PermGen, then reducing the number and size of your objects most likely won't help (because they will be taking up space in the Heap, not your PermGen)

This answer PermGen Out of Memory reasons should help with the causes of PermGen problems

like image 128
matt freake Avatar answered Mar 13 '26 10:03

matt freake



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!