Hi, and sorry for the poor english.
I create a native (win32) thread in a java process (by code injection,
with the CreateRemoteThread-LoadLibrary trick).
Next, I use the folowing APIs :
- JNI_GetCreatedJavaVMs
- AttachCurrentThread
- JAWT_GetAWT
Next, I use a win32 API (EnumWindows) and obtain a Windows Handle (type
HWND) belonging to the Java process.
Finally, I use GetComponent and get a "jobject" corresponding to the
'hwnd'.
It works: I am able to call some java methods.
My question:
What about the GC? Should I call some "free" method when I no longer
need to keep the "jobject" ?
--
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"
Gordon Beaton - 15 May 2006 13:01 GMT
> Should I call some "free" method when I no longer need to keep the
> "jobject" ?
Possibly...
In native code that that does not *return* to Java, you must
explicitly notify the garbage collector about unused object
references.
In native code that does return to Java, objects will automatically
become eligible for gc when they return, although if you'e creating
lots of objects locally you may need to notify gc before returning.
To notify the garbage collector, use DeleteLocalRef().
Note that the normal reachability rules also apply, so for references
passed outside the native method (in calls to other Java methods or in
return values etc), the objects won't actually become eligible for
collection until they are no longer reachable from those other places.
You can also use a combination of PushLocalFrame() and PopLocalFrame()
around a section of a native method, to get behaviour similar to that
of invoking a method (Push..) and returning from it (Pop...). The
garbage collector gets notified about any objects created within the
local frame when PopLocalFrame() is called.
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e