Skip to main content

Can you destroy an object?

5 replies [Last post]
kram
Offline
Joined: 2007-10-23
Points: 0

I have implemented a custom class which extends CustomNode called "movingCircle" that basically moves a circle in a direction.

I have a movingCircle[] in my app and it contains many of these movingCircle instances that all move in different directions.

I want to know if it is possible for each individual movingCircle to destroy itself once it gets off the screen (or possibly just delete itself from the array). Can this be done?

like:

<br />
if (object is off screen)<br />
  delete self from movingCircle[];<br />

Thanks!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kram
Offline
Joined: 2007-10-23
Points: 0

Ok so I think ive stopped every instance of each timeline that I have, but my game still grinds down to a halt after a while, even though I beleive that lots of objects should be getting cleaned up.

I ran the netbeans profiler, but with JavaFX its actually tough to figure out what is what, the biggest type of object created from a run of the game was the java.awt.geom.AffineTransform object, which Im guessing javaFX uses to transform its objects.

But I still dont know a good way to find out if the objects that shouldnt have any references are being cleaned up.

alexsch
Offline
Joined: 2007-07-12
Points: 0

Yes, you can.

kram
Offline
Joined: 2007-10-23
Points: 0

sorry for the delayed reply to this, but I have an array full of nodes, and this array is bound to the content of a Group{} in the main Frame of the app.

I have a timeline that does some calculations, and removes elements from the array sucessfully. This does reflect on the screen too, which is good. However, within each of my custom Node's that populate the array, they have their own "movementTimeline" Timeline which outputs their x and y corrds using System.out.println().

The issue is that when I delete them from the array, using the statement:

delete elem from nodeArray;

(it disappears from the screen) it does not stop outputting its x and y coords... so my question becomes, when i use the delete statement, should it destroy the object? or just remove it from the array? If it does not destroy it, how can i?

michael_heinrichs
Offline
Joined: 2007-11-15
Points: 0

The delete-statement removes the element from the sequence, it does not destroy it. In fact, there is no way to destroy an object directly. This is done automatically as soon as no references to the object exist anymore (just like in Java).

In your program, the timeline is still running and referencing the object. I think, you can either remove the timeline or simply stop it manually, whatever works better in your script.

(By the way, the containers are sequences, not arrays. There are very similiar, but there are some subtle differences.)

kram
Offline
Joined: 2007-10-23
Points: 0

Yeah I think that I will just set the references to null to fix it, thanks for the info.

Also, yeah I did mean sequence, its just the arrays from Java getting in my thoughts!