PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

Static var set in constructor

Open pvanassen opened this issue 10 years ago • 7 comments

When EvolutionForm is created a static var is set for the new instance. This must go very wrong at some point. https://github.com/Grover-c13/PokeGOAPI-Java/blob/Development/library/src/main/java/com/pokegoapi/api/pokemon/EvolutionForm.java#L10

pvanassen avatar Aug 08 '16 07:08 pvanassen

Looks like a potential memory leak.

FabianTerhorst avatar Aug 08 '16 07:08 FabianTerhorst

Doubt this will leak memory. I am certain weird things happen if you construct two of this objects and just them both.

pvanassen avatar Aug 08 '16 07:08 pvanassen

This potential memory leak is probably negligible but @pvanassen is right, to be honest this static field hasn't got any sense. W should remove 'static' and static 'getPokemonId' method or change it to non static.

mgorski-mg avatar Aug 08 '16 07:08 mgorski-mg

#508 Fixed

Jazed avatar Aug 08 '16 07:08 Jazed

In Java/Android a static variable or constant will not be garbage collected. It just stays there once the class that holds it is loaded via a class loader. The class loader is afaik always the same for all classes inside your app and its the one that has static references to all your classes (to e.g. MyInnerClass.class). Since the class loader does not go away your classes won't do that either since they are referenced & therefore not garbage collectable. Source: http://stackoverflow.com/questions/11908039/android-static-fields-and-memory-leaks

FabianTerhorst avatar Aug 08 '16 07:08 FabianTerhorst

@FabianTerhorst +1

mgorski-mg avatar Aug 08 '16 07:08 mgorski-mg

Merged

vmarchaud avatar Aug 08 '16 09:08 vmarchaud