Garbage Collector: this vs global Variables
BMM_Archive · July 15, 2026
Original Source
- Original title: Garbage Collector: this vs global Variables
- Original author: Eliaquim
- Original date: January 19, 2020
- Source thread: https://forums.rpgmakerweb.com/threads/garbage-collector-this-vs-global-variables.117429/
- Source forum path: Game Development Engines > RPG Maker Javascript Plugins > Learning Javascript
Summary
Hi people! I'm really trying to find out this information on the internet, but I can't find it. Since the keyword "this" let me access a property of a function outside of it, I want to know if the garbage collector behaves the same way as it behaves with global variables. So far as I know, javascript free the memory when an object or variable lost its reference.
Archived First Post
I'm really trying to find out this information on the internet, but I can't find it.
Since the keyword "this" let me access a property of a function outside of it, I want to know if the garbage collector behaves the same way as it behaves with global variables.
So far as I know, javascript free the memory when an object or variable lost its reference.
So in case of this keyword being used constantly, it behaves like a local variable that can be accessed outside the function? Or its behaves like a global variable(but not being global or local variable)?
My concern is performance.
So it's best for me to use this to change the property of a sprite for example:
this.carSprite.opacity = 100;
Or it's best for me to make a function that returns the opacity?
Function carSpriteOpacity(){
return 100;
}
Here is an example of information that tells me to use the "this" keyword to avoid using global variables.
But what confuses me is it's saying that it is different from the global variable, but it also can be accessed like a global variable outside of the function. So what I'm missing here?

Downloads / Referenced Files
RPG Maker Web attachments are mirrored locally when available. Other external links remain hosted by their original creator or third-party service.
- Local mirror: 110662-bddcd7907070d1c2083245dd2a62fb08.png
SHA-256:da85393c2e349e0b84d2a2ac2d1a3cce51d70be2b57bd426fd370ceb78eef992
Original attachment URL: https://forums.rpgmakerweb.com/attachments/screenshot_20200119-144318-png.131582/
Referenced Images / Attachments
Creator Claims / Removal
If you are the original creator and want this listing reassigned, edited, or removed, join BMMPlay and contact the moderators with proof that matches the original RPG Maker Web profile, linked GitHub, itch.io page, or another public creator identity.
Replies (0)
No replies yet.
Topic Summary
Loading summary...