Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (495)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  A sure way to kill off your Java program's used resources  (Read 2978 times)
0 Members and 1 Guest are viewing this topic.
Offline K.I.L.E.R

Senior Member




Java games rock!


« Posted 2005-08-28 05:47:55 »

We have all read about finalizers and the reasons why you shouldn't use it within your program.
However, I have a good way of making use of them.

If you have resources that need to be freed within your main program *hint* *hint*, then why not use finalizers in that one place?
It isn't going to do anything bad. Java will have to handle all the horrible exceptions and internal mess afterwards and not in the program.

BTW: I realise this isn't how you properly terminate threads. Smiley


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
class Main extends JFrame
{
        .....................

        public static void main(String[] elephants){
          .....................
        }

        ...........

        protected void finalize() throws Throwable
   {
      super.finalize();
                /*
                most unsafe code in the universe!
                then again, why should I care?
                this is the JVM's mess now, my program has already ended by the time this is called.
                this just makes it absolutely certain that everything is dead.
                */

      tmpThread.interrupt(); //will throw an exception
     tmpThread = null; //God no! Am I on drugs? Nulling a thread while it's quite possibly still RUNNING!!!
  }

         ................
}

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Jeff

JGO Coder




Got any cats?


« Reply #1 - Posted 2005-08-28 06:34:58 »

Because there is no gaurantee it will ever get called.

In fact, its likely not to as there is no need to collect the Main in most cases since at the moment the main ends so does the process.

While in a resouce tracked OS this *might* all be irrelevent, since the OS wil lcollect all the resources at  process end, ist still abd form as you are implying code will get called that wont be.  It CAN even be dangerous if you are expecting it to do domething like send another process an IPC message before the provess ends.


Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #2 - Posted 2005-08-28 06:42:27 »

Thanks.
I thought finalizers do get called, but are unpredictable in terms of time.
Looks as though I'm only partly right.

Now I can see why finalizers should never be used under any circumstance.
Why aren't they removed from Java alltogether?

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

JGO Kernel


Medals: 378
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #3 - Posted 2005-08-28 10:06:24 »

Because it's too late.

<edit> I think there's some massive irony somewhere in that statement, now I've posted it...

Cas Smiley

Offline Tzan

Junior Member





« Reply #4 - Posted 2005-08-29 15:02:23 »

Heh heh  Smiley
Offline Jeff

JGO Coder




Got any cats?


« Reply #5 - Posted 2005-08-29 23:59:30 »

Cas is absolutely right.  There are too many out there and we'd break code worse then it might already be broken if we removed them.

They CAn be used as a kind of hail-mary last ditch thing.  We do that in some of our JDK librarys.  we tell you that you MUST explicitly call a dispose() but we also call it in a finalizer as a "okay, you were an idiot but maybe we can save your bacon" sort of thing.  There are lots of philosophical arguments possible on whetehr this is a good or bad thing.

Since the generational colelctor though tehy have ahd an additional negative imapct in that they force an object to live past the eden-space even if its shoirt lived. For that reason you don't really ever want a finalizer on a short-lived object.






Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #6 - Posted 2005-08-30 08:37:35 »

I think Java needs a lot of remodelling.

I hope Java 2.0(Not Java 2, but Java 2.0.0, or should I call it Java 3?) will eliminate deprecated methods, implement runtime generics and remove finalizers among many other things.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #7 - Posted 2005-08-30 09:35:43 »

I hope Java 2.0(Not Java 2, but Java 2.0.0, or should I call it Java 3?) will eliminate deprecated methods, implement runtime generics and remove finalizers among many other things.

I hope it doesn't  Tongue
Imagine how much software that would break.

Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #8 - Posted 2005-08-31 05:21:14 »

Imagine how much future software it would make better. Smiley
You could argue that there wouldn't be any more future software if it breaks compatibility.

Damned if you do, damned if you don't.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Jeff

JGO Coder




Got any cats?


« Reply #9 - Posted 2005-08-31 06:13:19 »

At Some Point...

When the VM really is doing everything everyoen wants of the current Java, I could see an argumetn for a new project that took everything we've learned and started over.  It would probably be better to name it something different to make it clear that it was a totally new fork...

Anyone for Java++  Grin

Got a question about Java and game programming?  Just new to the Java Game Development Community?  Try my FAQ.  Its likely you'll learn something!

http://wiki.java.net/bin/view/Games/JeffFAQ
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #10 - Posted 2005-08-31 06:36:21 »

Quote
When the VM really is doing everything everyoen wants of the current Java[...]

You can see that happening?
You're definitely an optimist. :lol:

Someone will always ask for more.
Eventually you're probably going to have a VM that programs itself at the command of a human thought.
Even that wouldn't be enough for some people.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #11 - Posted 2005-08-31 08:00:48 »

Imagine how much future software it would make better. Smiley

I don't see how taking out finalizers and deprecated methods makes future software better. Future software are not supposed to use deprecated methods or finalizers anyway. Taking them out might get rid of some compiler warnings, but will mostly just break existing code. Not worth it IMHO.

Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #12 - Posted 2005-08-31 09:32:35 »

Quote
Someone will always ask for more.
Eventually you're probably going to have a VM that programs itself at the command of a human thought.

What the world needs is more dreamers...

Kev

Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #13 - Posted 2005-08-31 10:17:14 »

I believe the problem is that there are too many dreamers.
What the world needs is people having realistic expectations and reasonable demands.


Quote
Someone will always ask for more.
Eventually you're probably going to have a VM that programs itself at the command of a human thought.

What the world needs is more dreamers...

Kev

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 798
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #14 - Posted 2005-08-31 10:53:55 »

I believe the problem is that there are too many dreamers.
What the world needs is people having realistic expectations and reasonable demands.

Then we'd still be throwing sticks and stones at rabbits in thick forests.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline K.I.L.E.R

Senior Member




Java games rock!


« Reply #15 - Posted 2005-08-31 11:01:49 »

No we wont. I said that we have "too many dreamers".


I believe the problem is that there are too many dreamers.
What the world needs is people having realistic expectations and reasonable demands.

Then we'd still be throwing sticks and stones at rabbits in thick forests.

Vorax:
Is there a name for a "redneck" programmer?

Jeff:
Unemployed. Wink
Offline kevglass

JGO Kernel


Medals: 164
Projects: 23
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #16 - Posted 2005-08-31 11:40:40 »

Quote
I believe the problem is that there are too many dreamers.
What the world needs is people having realistic expectations and reasonable demands.

It was actually a compliment - for the imagination of the comment.

What the world probably needs is less people trying to decide what the world needs Smiley

Kev

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Dwinin (29 views)
2014-09-12 09:08:26

Norakomi (57 views)
2014-09-10 13:57:51

TehJavaDev (76 views)
2014-09-10 06:39:09

Tekkerue (38 views)
2014-09-09 02:24:56

mitcheeb (58 views)
2014-09-08 06:06:29

BurntPizza (45 views)
2014-09-07 01:13:42

Longarmx (30 views)
2014-09-07 01:12:14

Longarmx (35 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19

mitcheeb (40 views)
2014-09-04 23:08:59
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!