Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

how to free memory

Thread view: 
vidhi - 03 Jan 2006 08:16 GMT
we have a java application game starts through applet, which initiates
sevral threads. Our poblem is when user close game window but applet
loader browser window opened the game is not actualy closed but the
threades are still running which causes problems. As
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); of frame is not working
while working with applet as it shows Security Exception.
plsese help me.
vidhi
Luke Meyers - 03 Jan 2006 09:07 GMT
It is inherently unsafe to issue external shutdown commands to a
thread.  See the documentation for the deprecated methods on Thread to
understand why, and to learn about the appropriate idiom (looping and
checking a conditional).

Luke
vidhi - 03 Jan 2006 09:13 GMT
i know its already implemented but when user close the window
intentionally then what we wish is to unload the whole game
immediately, although we set the appose the conditions it still regised
in the memory and that is the problem.
ziki - 03 Jan 2006 10:48 GMT
Hi,
you can try the folowing:
When the user close the window you can send an event msg to your thread
that will perform special code that you will write for this case and
than he will quit from the run method (will shutdown/stop) and then the
garbage collector will do the final work...
Luke Meyers - 03 Jan 2006 10:49 GMT
> i know its already implemented but when user close the window
> intentionally then what we wish is to unload the whole game
> immediately, although we set the appose the conditions it still regised
> in the memory and that is the problem.

Memory deallocation isn't your problem -- Java is a garbage-collected
language, so once the references go away the memory is freed (not
instantly, but your responsibility ends).  It's possible to have memory
leaks by keeping references around accidentally in various ways, but
that's another matter.  Your problem is, if I understand you correctly,
that you've spun off multiple threads and they're not all stopping when
your main thread stops due to the window closing.

The scheme I recommended is a fairly universal idiom for managing
thread lifespan.  Without seeing any code to the contrary, I must
assume that there is a flaw in your implementation, because the idiom
is sound.  Perhaps when you set and/or check the variable upon which
the condition hinges, you are not performing appropriate
synchronization.

Luke

P.S. Every time I get on the topic of Java synchronization, I have to
plug Doug Lea's book "Concurrent Programming in Java."  It's rad, read
it.
vidhi - 03 Jan 2006 11:07 GMT
u get the problem, actualy the main thread is stoped due to user action
of closing window if i stoped thread with altering condition threads
might be stoped but they still occupied memory, for example if any
sound file is playing then it continusly stated play this give a big
hint that why memory used is not freed as all the images and other
files are still in the memory.

i already used to null all the main objects and run Runtime.gc() &
System.gc() methods for garbegh collection.

still same.
Thomas Schodt - 03 Jan 2006 14:11 GMT
> u get the problem, actualy the main thread is stoped due to user action
> of closing window if i stoped thread with altering condition threads
[quoted text clipped - 5 lines]
> i already used to null all the main objects and run Runtime.gc() &
> System.gc() methods for garbegh collection.

<http://forum.java.sun.com/thread.jspa?threadID=695880>
Roedy Green - 03 Jan 2006 22:40 GMT
>It's possible to have memory
>leaks by keeping references around accidentally in various ways, but
>that's another matter.  

see http://mindprod.com/jgloss/packratting.html
for various places you may accidentally hold onto references you don't
really need.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.