vinhkhuc / JFastText

Java interface for fastText

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

the problem with model replace

Trangle opened this issue · comments

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.

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.

@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.