All java class wrapping a native object must call dispose at destruction.

This commit is contained in:
Matthieu Gautier 2023-01-24 16:01:47 +01:00
parent 1dd170bd59
commit 150af85a7a
14 changed files with 49 additions and 12 deletions

View File

@ -45,6 +45,10 @@ public class Server
setNativeServer(library);
}
@Override
protected void finalize() { dispose(); }
private native void setNativeServer(Library library);
private native void dispose();
private long nativeHandle;

View File

@ -104,6 +104,9 @@ public class Archive
private native void setNativeArchiveByFD(FileDescriptor fd);
private native void setNativeArchiveEmbedded(FileDescriptor fd, long offset, long size);
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper

View File

@ -26,9 +26,10 @@ public class Blob
public native String getData();
public native long size();
protected void finalize() {
dispose();
}
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper

View File

@ -31,9 +31,8 @@ public class Entry
public native Item getRedirect();
public native Entry getRedirectEntry();
protected void finalize() {
dispose();
}
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper

View File

@ -29,6 +29,10 @@ public class EntryIterator implements Iterator<Entry>
public native boolean hasNext();
public native Entry next();
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -30,9 +30,8 @@ public class Item
public native Blob getData();
public native long getSize();
protected void finalize() {
dispose();
}
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper

View File

@ -28,6 +28,10 @@ public class Query
public native Query setQuery(String query);
public native Query setGeorange(float latitude, float longitute, float distance);
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -26,6 +26,10 @@ public class Search
public native SearchIterator getResults(int start, int maxResults);
public native long getEstimatedMatches();
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -36,6 +36,10 @@ public class SearchIterator implements Iterator<Entry>
public native boolean hasNext();
public native Entry next();
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -51,6 +51,10 @@ public class Searcher
private native void setNativeSearcher(Archive archive);
private native void setNativeSearcherMulti(Archive[] archives);
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -26,9 +26,8 @@ public class SuggestionItem
public native String getSnippet();
public native boolean hasSnippet();
protected void finalize() {
dispose();
}
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper

View File

@ -27,6 +27,10 @@ public class SuggestionIterator implements Iterator<SuggestionItem>
public native boolean hasNext();
public native SuggestionItem next();
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -26,6 +26,10 @@ public class SuggestionSearch
public native SuggestionIterator getResults(int start, int maxResults);
public native long getEstimatedMatches();
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();

View File

@ -40,6 +40,10 @@ public class SuggestionSearcher
private native void setNativeSearcher(Archive archive);
@Override
protected void finalize() { dispose(); }
///--------- The wrapper thing
// To delete our native wrapper
public native void dispose();