'dispose' in JS is removeChild?

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Back in RGSS3, there's a function in array where you can do dispose:

class Game_Temp attr_accessor :r_effect_sprites alias r_effect_initialize initialize def initialize r_effect_initialize @r_effect_sprites = [] end def dispose_r_effect @r_effect_sprites.each{|sprite| sprite.dispose} @r_effect_sprites = [] endendI noticed that it disposed the sprites being pushed, is it the same with removeChild?

This line of code in particular:

@r_effect_sprites.each{|sprite| sprite.dispose}How well do you translate it in JavaScript?
 
Last edited by a moderator:

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
Looking through the default scripts, I don't see any images being disposed of.  I suspect it's relying on the garbage collector, which gets rid of anything that is no longer referenced.

I'm curious to see if there's a "right" way.
 

nio kasgami

VampCat
Veteran
Joined
May 21, 2013
Messages
8,949
Reaction score
3,042
First Language
French
Primarily Uses
RMMV
actually...dispose concept just not exist in MV because it's take times to load so they need to keep in memory once they are loaded. it's the browser issue sadly.

because if each time you dispose a picture you erase it and in MV that's would not work wells 

the ways of "dispose" a sprite in a ways is to setup the bitmap like this :

this.sprite.bitmap = ImageManager.loadsomething('');that's would stop getting the picture though it's also necessary to make it invisible for avoid any can't get noname.png picture error by setting like this :

this.sprite.visible = false;or setup method who STOP the system from drawing the bitmap.

like this method I done in my bust script : 

//----------------------------------------------------------------------------// ○ new function: drawMessageBust//----------------------------------------------------------------------------Window_Message.prototype.drawMessageBust = function() { if ($gameMessage.bustName() != ""){ this.spritebust.bitmap = ImageManager.loadBust($gameMessage.bustName() + '_' + $gameMessage.bustIndex()); this.spritebust.visible = true; }else { this.spritebust.bitmap = ImageManager.loadBust(""); this.spritebust.visible = false; }}; but material are auto "removed" but keep in memory at the end of the scene.

but yeah this.removeChild(varname); is the way to erase totally from the system memory.

Though disposing in MV would provoke lags use "visible" for make something invisible.
 

Another Fen

Veteran
Veteran
Joined
Jan 23, 2013
Messages
564
Reaction score
275
First Language
German
Primarily Uses
First, I don't have any expertise on this matter and just looked through the plugin system a bit, so what I'm telling might be completely false:

In the previous makers, disposing a sprite was necessary in order to remove the sprite from the internal "to draw" list. Otherwise the sprite would continue to appear on the screen until the garbage collector cleaned it up, which could take a while.

In MV, sprites have to be added to the current scene instead (using the addChild method). Once a scene is replaced the sprites attached to it are no longer drawn to the screen, so you don't have to dispose them explicitely.
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
MV uses canvas to render images, which internally are just ordinary <img> html tags. They are cached on the user's pc, just like any other image on any website you visit (at least that's how i see it, WebGL might be a bit different).
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Thanks for all the info. I might need to read more, I'll check on it later how it works.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
We have concepts of push (SceneManager), pop (SceneManager), addWindow (Scene), addChild(Scene and Sprite) and I believe removeChild (Scene and Sprite)
 

Tsukihime

Veteran
Veteran
Joined
Jun 30, 2012
Messages
8,564
Reaction score
3,846
First Language
English
I've been told that WebGL objects are not disposed unless you explicitly dispose them, so even if the sprite itself is disposed, the underlying webgl object will stay around.


But I have not checked this myself.
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
usually garbage collection will kick in when you call "remove" or a "dispose" function ... if it stuck around that would (or could) cause performance issues.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
How about new sprites defined? For example, I noticed on Scene_Gameover that the sprite being called there was never, 'removed' or 'disposed'. If I create a new sprite in the title screen or in the menu, should I still do the same thing like back in RGSS where I have to remove it during termination, or just leave them like that?
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
How about new sprites defined? For example, I noticed on Scene_Gameover that the sprite being called there was never, 'removed' or 'disposed'. If I create a new sprite in the title screen or in the menu, should I still do the same thing like back in RGSS where I have to remove it during termination, or just leave them like that?
Some sprites and assets will stick around at the game or pixis discretion. It might also be the fact that the original programmers got lazy and didn't clean up. But generally when you switch from scene A to scene B the only one, if it is popped off the array of scenes is cleaned up. The same goes for sprites and windows.

For example, open up the menu, open up items you now have about 2 -3 scenes running. Close the items. GC (garbage collection) has cleaned up the item scene. close menu, same thing. switch maps. same thing for all maps and sprites that were on that map.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
I don't think it's because they got lazy and didn't clean up. From the looks of it, they've pretty much just converted the same logic in Ace from Ruby to Javascript - classes are the same, method names are similar, most of the logic seems to be similar. So to NOT dispose of a sprite in Javascript, when it was specifically done in Ruby, seems to be a deliberate decision, and I assumed that decision was that JS handles garbage collection differently and they chose to hand over that responsibility to the JS garbage collector.


I'm not saying the way they've done it is right - reports of lagging after changing scenes, and memory leaks, might indicate that it's not.


Even though a scene is cleaned up, it doesn't mean the resources that were used by that scene are cleaned up - they're still in the cache, unless there's something that removes them.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
That is my worry Shaz, because in a plugin I am writing, there's like 17 custom sprites running, and I don't find any way to remove or dispose them correctly, only by removeChild and that's it :/
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
That is my worry Shaz, because in a plugin I am writing, there's like 17 custom sprites running, and I don't find any way to remove or dispose them correctly, only by removeChild and that's it :/
removeChild will dispose of the sprite properly. Once its no longer on the scene the GC is called and its cleaned up. 
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
It is still in the cache, which means it won't be removed.


Rather ... the sprite will be removed, but the bitmap that was attached to the sprite will still be in the cache, so you're really not getting much back, as that's what's taking up all the memory.
 
Last edited by a moderator:

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
its removed when the scene is changed ...
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
First Language
English
Primarily Uses
RMMV
The bitmap in the cache? Where is it removed? I'm not seeing it.


The only thing that removes cached images is ImageManager.prototype.clear, and that's not called from anywhere.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
The bitmap in the cache? Where is it removed? I'm not seeing it.

The only thing that removes cached images is ImageManager.prototype.clear, and that's not called from anywhere.
Is there an approach to dispose the bitmap? From what I know, this caused so much problem back in Ace. It might lag in a mobile version if these sprites just stays there for some reason.
 

Galenmereth

Retired
Veteran
Joined
May 15, 2013
Messages
2,248
Reaction score
2,158
First Language
English
Primarily Uses
N/A
Just remove your references to the sprite object, so that the reference to its bitmap instance is also removed. Using removeChild will remove it from its parent's update queue, but if you have other references to it -- like anoter variable -- you want to make sure they're cleared too. Clearing a variable reference would be something like 

_mySpriteReference = null; Then there's no reference to the bitmap object, and its instance is cleaned up by the GC. Of course the bitmap will still be in the cache -- we want that, for faster loading when/if we want to instantiate instances of it again.
 

Milena

The woman of many questions
Veteran
Joined
Jan 26, 2014
Messages
1,281
Reaction score
106
First Language
Irish
Primarily Uses
N/A
Just remove your references to the sprite object, so that the reference to its bitmap instance is also removed. Using removeChild will remove it from its parent's update queue, but if you have other references to it -- like anoter variable -- you want to make sure they're cleared too. Clearing a variable reference would be something like 

_mySpriteReference = null; Then there's no reference to the bitmap object, and its instance is cleaned up by the GC. Of course the bitmap will still be in the cache -- we want that, for faster loading when/if we want to instantiate instances of it again.
I'll be using that :) thanks. What I was doing back then was just removing it via the removeChild, and I am having doubts if I was really removing it or just taking it out there, but the bitmaps still on the window.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,986
Members
137,561
Latest member
visploo100
Top