ReadAsBinary vs loadStaticModel

So i am reading google news model. ReadAsBinary takes 3.5 gig of memory, but the loadStaticModel takes up like 10gigs. What is happening?

This is because of the different ways the model is loaded, readAsBinary can read a model as binary data, while loadStaticModel, depending on the actual model format, will do a few different things.

I guess that you are loading a string serialized model, so in that case it has to parse hundreds of strings into floats for every single word. This creates a whole lot more String objects on the JVM heap, which themselves require more memory than the binary data.

That memory should be freed on the next GC run, but if you have a lot of memory, you might have not that much GC pressure and it might take a while. You can trigger it manually with System.gc() after you’ve loaded the model.