Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with closing RAMDictionary. #3

Open
Kleanthi opened this issue Mar 21, 2018 · 3 comments
Open

Problem with closing RAMDictionary. #3

Kleanthi opened this issue Mar 21, 2018 · 3 comments

Comments

@Kleanthi
Copy link

Kleanthi commented Mar 21, 2018

Here is my code:

String wordNetFolder = System.getProperty("user.dir") + "/src/main/resources/wordnet/dict/";
File exFile = new File(wordNetFolder + "JWI_Export_.wn");
IRAMDictionary dictionary;
dictionary = new RAMDictionary(dictionaryFolder);
dictionary.setLoadPolicy(ILoadPolicy.IMMEDIATE_LOAD);
try {
    dictionary.open();
    dictionary.export(new FileOutputStream(exFile));
    dictionary.close();
} catch (IOException e1) {
    e1.printStackTrace();
}

When I do
assert(dictionary.isOpen() == false);

I get java.lang.AssertionError because the dictionary seems to still be open.
Why is this happening?

I am using the 2.4.0 version.

@rm-hull
Copy link
Owner

rm-hull commented Mar 21, 2018

I would refactor your code as follows:

String wordNetFolder = System.getProperty("user.dir") + "/src/main/resources/wordnet/dict/";
File exFile = new File(wordNetFolder + "JWI_Export_.wn");
IRAMDictionary dictionary;
dictionary = new RAMDictionary(dictionaryFolder);
dictionary.setLoadPolicy(ILoadPolicy.IMMEDIATE_LOAD);
try {
    dictionary.open();
     dictionary.export(new FileOutputStream(exFile));
} catch (IOException e1) {
    e1.printStackTrace();
} finally {
    if (dictionary != null) {
        dictionary.close();
    }
}

@Kleanthi
Copy link
Author

Thanks for you quick reply. I have done exactly what you suggested, but I also added a print to check if the dictionary is actually not null, after if (dictionary != null) . It seems that the dictionary is not null but it is still open after I call the function to close it.

@Kleanthi
Copy link
Author

Kleanthi commented Mar 21, 2018

Sorry to bother again in such a short notice, but I have been doing some digging inside your classes and apparently in https://github.com/rm-hull/jwi/blob/master/src/edu/mit/jwi/RAMDictionary.java#L448 the state != LifecycleState.CLOSING should be state == LifecycleState.CLOSING, otherwise the close() function returns without actually setting the loader and the data into null, and without closing the backing and without changing the state of the dictionary in CLOSE. As a result, the dictionary stays loaded in memory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants