3 ms·
Static variables. Know that you should be extremely cautious with these, especially if you're using them to store big maps or dictionaries or things like that.
by coding123 4y ago
Static variables. Know that you should be extremely cautious with these, especially if you're using them to store big maps or dictionaries or things like that. Beyond statics, honestly, never ran into anything else that's not cured by changing your command line a bit.
- dehrmann 4y agoClasses can also be GCed in Java, but obviously only if they're no longer referenced.
- bberrry 4y agoPresumably if you're creating a large map in memory it's being used, no? Or did you have something static that was really only used during startup?
- Brystephor 4y agoWhy are these relevant or special for the GC in a "gotcha" manner?
- karmakaze 4y agoBecause a static reference causes objects referenced by it to never be GC'd. As a simple hack, someone might add a singleton implemented as a static field of a class. That reference could be/have a structure/collection that accumulates and never gets freed. You can find these things using the Java Memory Analyzer and the OQL it supports. Sometimes easy sometimes tricky.