Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
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  
  graphics obj during rendering  (Read 1111 times)
0 Members and 1 Guest are viewing this topic.
Offline Kommi

Junior Member




All opinions will be lined up and shot!


« Posted 2004-04-10 17:08:49 »

I was just thinking about this in terms of garabge collection. In my rendering loop I have a
Graphics g = bs.getDrawGraphics();
and then later
g.dispose();
So each render I crate and dispose of the graphics object. Is this a proper way of rendering? Wouldn't the constant creation and disposing of the object trigger the gabage collection at a bad time?

Kommi
Offline kevglass
« League of Dukes »

JGO Kernel


Medals: 54
Projects: 20


Mentally unstable, best avoided.


« Reply #1 - Posted 2004-04-10 17:13:07 »

bs.getDrawGraphics() doesn't nessersaryly create a graphics object. In the same way g.dispose() doesn't mean that the graphics object would be destroyed and garbaged collected.

Kev

Offline D.t.O

Junior Member




Psych'd about Java Games


« Reply #2 - Posted 2004-04-10 20:36:14 »

Is there any way to more or less label an object so that you can be sure it will be garbage collected on the next run of the garbage collector?

Enjoy.
Regards,
     - D.t.O
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline Jeff

JGO Coder




Got any cats?


« Reply #3 - Posted 2004-04-10 21:20:57 »

Absolutely not.

GC is always at the dsicretion of the VM. It has to be to allow for efficient gc algortihyms.

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 D.t.O

Junior Member




Psych'd about Java Games


« Reply #4 - Posted 2004-04-10 23:12:08 »

dang. oh well. Sad

Thanks for the info though.

Enjoy.
Regards,
     - D.t.O
Offline cfmdobbie

Senior Member




Who, me?


« Reply #5 - Posted 2004-04-13 21:41:16 »

If the object is short-lived, the VM will notice and make special considerations for it.  You shouldn't get any GC pause from short-lived objects with a modern VM.

When starting programming in Java, the first rule of memory management is just not to think about it - a number of very intelligent engineers have designed the VM such that you shouldn't have to.

Hellomynameis Charlie Dobbie.
Offline trembovetski

Senior Member




If only I knew what I'm talking about!


« Reply #6 - Posted 2004-04-14 04:13:02 »

A note: a Graphics object is a graphics context and is pretty lightweight as such, it just holds a state.

It's better to obtain a new graphics context every time, and then dispose of it.

Offline D.t.O

Junior Member




Psych'd about Java Games


« Reply #7 - Posted 2004-04-14 04:24:15 »

When you call foo.getDrawGraphics() twice, do you get two separately allocated Graphics objects, or just one object that is returned twice? Is this behavior constant, i.e. do you always get the same behavior?

Enjoy.
Regards,
     - D.t.O
Offline Jeff

JGO Coder




Got any cats?


« Reply #8 - Posted 2004-04-14 04:27:25 »

Unless it says soemthing specific in the Java doc that woudl be VM dependant.

Anything not in the JavaDocs is VM dependant by definition Wink

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 D.t.O

Junior Member




Psych'd about Java Games


« Reply #9 - Posted 2004-04-14 04:31:58 »

I edited my post while you were writing, but I guess you answered the second question too Grin
Thanks Smiley

Enjoy.
Regards,
     - D.t.O
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (80 views)
2013-05-17 21:29:12

alaslipknot (89 views)
2013-05-16 21:24:48

gouessej (122 views)
2013-05-16 00:53:38

gouessej (114 views)
2013-05-16 00:17:58

theagentd (126 views)
2013-05-15 15:01:13

theagentd (113 views)
2013-05-15 15:00:54

StreetDoggy (158 views)
2013-05-14 15:56:26

kutucuk (180 views)
2013-05-12 17:10:36

kutucuk (180 views)
2013-05-12 15:36:09

UnluckyDevil (186 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.108 seconds with 21 queries.