vinhkhuc / JFastText

Java interface for fastText
Other
229 stars 100 forks source link

the problem with model replace #21

Open Trangle opened 7 years ago

Trangle commented 7 years ago

I wrote my code like JFastText jft = new JFastText(); jft.loadModel(MODEL_FILE); int cnt = 0; while(true) { System.out.println("new: " + (++cnt)); JFastText after = new JFastText(); after.loadModel(MODEL_FILE); JFastText before = jft; jft = after; // after = null; System.out.println("done"); before.unloadModel(); // before = null; System.gc(); }

then this process will exit with error by null pointer deallocate, is there any resolution to this case? Thank you.

Trangle commented 7 years ago

@vinhkhuc

villahp commented 7 years ago

Hi @Trangle, Your code seem to swap two models, so that I think you should try to swap model_file, which is a path to your model file, instead of exchange model variables.

Trangle commented 7 years ago

@villahp Yes, I need to swap two models to make the first model still work while the new model is loading. The problem is that when encountered java gc, in the process of memory release, the object with no memory malloc will be released because the destructor in fb c++ version. I solved the problem by relpace the c++ version of fasttext to the newest one, which add size judge in ~QMatrix.