• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

I have a java script question.

CesarZ

Well-Known Member
Joined
Sep 20, 2012
Messages
272
Solutions
4
Reaction score
66
if my code is.
LUA:
class Monster{
    constructor(health, level, outfit){
    this.m_health = health,
    this.m_level = level,
    this.m_outfit = outfit,
    this.m_outfit = New Outfit(outfit);
    }
}


//My question is....
//If i place a monster on the map of my game.

const Monster_placer = [
    New Monster(100, 30, 2)
];

//if i delete one by using

this.Monster_placer.pop(1);

//Would it also delete that class that says
    New Outfit(outfit);
   
//located inside that Monster class?


my Goal here is to save as much memory and dump all trash if they aren't being use on any of my projects with JavaScript. I'm trying to understand how it works when it comes to memory use.

i don't know if BEFORE i pop the monster out, i should pop that "New Outfit" class out of there and then pop the monster out.

I don't know if you all get me or i have to explain my self better. let me know your thoughts thanks
 
You can try following code

class Outfit {
constructor(name) {
this.name = name;
}
}

class Monster {
constructor(health, level, outfit) {
this.m_health = health;
this.m_level = level;
this.m_outfit = new Outfit(outfit); // Create Outfit instance inside Monster
}
}

// Placing a Monster on the map
const Monster_placer = [
new Monster(100, 30, 2)
];

// Removing the last Monster (and its Outfit) from the map
Monster_placer.pop(); // Removes the last Monster object and its associated Outfit
 
What you can try yourself is to create a million monsters, then remove them. You will see then the memory usage and (if) there are any leaks :)
 
Back
Top