SAMPLE: SmartGC Uses an ATL Server to Trigger Java Garbage Collection
ID: Q231294
|
The information in this article applies to:
-
Microsoft Visual J++, version 6.0
-
Microsoft Visual C++, 32-bit Editions, version 6.0
-
Microsoft virtual machine
-
Microsoft Windows NT, versions 4.0, 4.0 SP4
SUMMARY
Java applications can register a sink with the JVMmem ActiveX Template Library (ATL) server, which periodically monitors memory load. When a memory threshold is exceeded, the server fires a notification event to the Java application indicating that the Java garbage collector should be invoked.
SmartGC.exe provides a foundation for Java applications to more optimally control garbage collection. Since Java garbage collection is triggered by Virtual Memory (VM) usage, some applications may run more efficiently if garbage collection is triggered on available RAM or the process Working Set size.
MORE INFORMATION
The following files are available for download from the Microsoft
Download Center. Click the file names below to download the files:
Gc.exe
SmartGc.exe
For more information about how to download files from the Microsoft
Download Center, please visit the Download Center at the following Web
address
http://www.microsoft.com/downloads/search.asp
and then click How to use the Microsoft Download Center.SmartGC Files |
Size in Bytes |
CCheckMem.h |
1866 |
CheckMem.cpp |
3779 |
CheckMem.h |
2193 |
CheckMem.rgs |
637 |
dlldata.c |
839 |
JVMmemMod.aps |
3736 |
JVMmemMod.cpp |
1970 |
JVMmemMod.def |
226 |
JVMmemMod.dsp |
13088 |
JVMmemMod.dsw |
541 |
JVMmemMod.h |
19900 |
JVMmemMod.idl |
2430 |
JVMmemMod.rc |
2861 |
JVMmemMod.tlb |
3376 |
JVMmemModCP.h |
917 |
JVMmemModps.def |
251 |
JVMmemModps.mk |
478 |
JVMmemMod_i.c |
1272 |
JVMmemMod_p.c |
21624 |
memory.pmc |
758 |
PSAPI.H |
4172 |
PSAPI.LIB |
19790 |
resource.h |
502 |
rm.cpp |
0 |
StdAfx.cpp |
315 |
StdAfx.h |
908 |
The following steps describe how to use SmartGC.exe.
- Build the ATL project. This creates and registers the JVMmem ATL DLL server.
- Open the Java project, select Add COM Wrapper from the Project menu.
- Select JVMmemMod 1.0 Type Library from the list of installed COM Components.
- Build the sample.
You will get better results if you run the sample outside the Visual J++ IDE; that is, from Explorer:
- Click the Create button a few times until the Current Available Physical Memory is at least 5 MB lower than the initial Available Physical Memory.
- Click Delete All. This will initialize the JVMmem server to monitor Available Physical Memory.
After about a minute the 'Object Cnt:' should match the 'Vector Cnt:' and the Current Working Set and Available Physical Memory should return near initial Levels.
NOTE: All of the memory statements in this article assume other applications are not consuming more memory while you run the sample test. Obviously, if you start several large applications, the current available memory will be lowered regardless of GC activity on the test sample.
The current Available memory and current working set may take some time to return to initial levels, as Windows NT does not immediately trim the working set if there is no need for RAM.
Notice the program calls SetProcessWorkingSetSize in the constructor to encourage Windows NT to limit the maximum Working Set.
Use the following steps to test that the GC sink routine is actually forcing the freeing of memory and objects:
- Click the Stop Timer button. Notice it now changes to "Start Timer."
- Create and delete several objects so the Object count is 30 but the Vector Count is zero. The memory and objects will not be garbage collected.
- After waiting until your convinced that no garbage collection will take place, click Start Timer button. Within about a minute you should see the Object Count return to zero and corresponding memory freed.
REFERENCES
For more information, see the following article in the Microsoft Knowledge Base:
Q231183 SAMPLE: Clean Up Java Resources Automatically with Gc.exe
For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java,
please see the following pages on the Microsoft Technical Support site:
http://support.microsoft.com/support/visualj/
http://support.microsoft.com/support/java/
© Microsoft Corporation 1999, All Rights Reserved.
Contributions by Rick Anderson, Microsoft Corporation
Additional query words:
Keywords : kbCOMt kbJava kbJavaVM kbJNative kbNTOS400 kbSDKJava kbVC kbVJ kbGrpJava kbDSupport
Version : WINDOWS:6.0; winnt:4.0,4.0 SP4,6.0
Platform : WINDOWS winnt
Issue type : kbhowto