This week's book giveaway is in the Mac OS forum. We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line! See this thread for details.
Hello, I'm working on a Java application and have been trying to reduce the overall memory use. According to the Windows Task Manager, when my application first starts up it uses about 45,000 kb. If I reduce the program window (by clicking on the icon in the upper right-hand corner), and then restore it, the memory usage drops to about 25,000 kb. I've got two questions about this: 1) Why is this happening? 2) Is there any way I can make this happen automatically when the program starts up, so that it uses the smaller amount of memory from the outset, without having to reduce it manually? Thanks for any suggestions! Best, David
I'm not too sure, but I'd guess that the building of the window and application startup leave a lot of garbage in memory that was only necessary to initialize stuff. I'm no GUI mechanics expert, but I'm sure there are all sorts of temporary objects created to format and diplay a GUI. Just a thought: Start the program up with the java runtime option -verbose:gc to see if the garbage collector runs at all before you minimize the window. If not (or if the garbage collector runs so early in the process that it becomes ineffective), it will proably help to call System.gc() in your code shortly after opening the window.
Plus, in Swing everything is double-buffered. This is done so that all the GUI components are redrawn smoothly and you can't see any components in a half-drawn state. This is done basically by using a buffer image in memory that everything is drawn to, and when it is done drawing, this buffer image is painted to the real screen image. Since the buffer image is the same size as the real frame, the amount of memory taken up by the buffer increases as the frame gets larger. [ May 20, 2003: Message edited by: Nathan Pruett ]
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Start the program up with the java runtime option -verbose:gc One thing to be aware of here is that the memory use reported by -verbose:gc refers to the allocated heap memory. The memory use reported by Task Manager refers to total memory allocated to a process - which is generally larger. In particular, any time your java classes invoke a native method (directly or indirectly) they may end up consuming memory somewhere outside the heap, not directly managed by the JVM. It's even possible that in some situations the memory may not appear in Task Manager as allocated to java.exe, but rather to some other process. (Dunno a good example of this; I think I've seen this sort of thing in Unix once or twice, not Windows - I'm just saying it could happen.) So pay attention to both the -verbose:gc output and the Task Manager display to get a complete picture.
"I'm not back." - Bill Harding, Twister
subject: Reducing window reduces memory use - why?