|
|
|||||||||||||
Class Rootpublic class Root { // Methods public static int alloc(Object object); public static void free(int root); public static Object get(int root); } This class allows you to create an opaque 32-bit root handle to any Java object. A root handle prevents the contained Java object from being reclaimed by garbage collection, so that the Java object can be safely stored in native data structures. This technique is valuable when using DLL functions that take callback parameters. For example, when a callback will be used across function calls, you need to protect the Callback object from being reclaimed. You should wrap the Callback inside a root handle and then explicitly free the root handle when you no longer need the Callback. Suppose you have declared a class called EnumWindowsProc that extends Callback and that will be used across function calls. To protect an instance of this class from garbage collection, you could write the following code. EnumWindowsProc MyCallback = new EnumWindowsProc; int rootHandle = Root.alloc(MyCallback); // use the Callback across function calls // until you're done Root.free(rootHandle); For more information about declaring and invoking DLL functions that take callbacks, see the Callbacks section of the Microsoft® J/Direct article. Methodsallocpublic static int alloc(Object object); freepublic static void free(int root); getpublic static Object get(int root);
|
© 1998 Microsoft Corporation. All rights reserved. Terms of use. |