Sign In Register

How can we help you today?

Start a new topic
Answered

How does the JS API work in the backend? (memory management)

 Hi,


This is more of a cpu/memory management question.


I'm assuming that every time a user calls a GS Event, a new instance of it is run.


I have an event E that requires module M.

Here's the example code:
function M_MyModule () { 
    this.PrivateMethodA = function() {
        // some code here
    };
};

M_MyModule.prototype.PublicMethodB = function () {
    // some code here
};

M_MyModule.prototype.PublicMethodC = function () {
    // some code here
}

 And my Event that requires my module looks like this.

// this is the event class
gs_load("M_MyModule");
var myModule = new M_MyModule();
// some code to invoke methods in ^
So what I'm wondering is, does a new instance of my event and module get created every time a player calls said event? If yes, then I do not have to worry about having too many PrivateMethodA's right? Or is some form of the API cached, such as all prototype methods get written into memory, and are referenced from another script that handles these API calls?

Bigger question: Should I even bother worrying about this? Is my thought process off tangent?
Any insight would be wonderful. Thanks.


 

 



Best Answer
Hey Davendra,

You are right, the modules are cached and used in reference for subsequent calls from those scripts and modules. Variables passing through modules are unique to the context of each event though, so they will not be shared between events running the same module at the same time.
So, you dont need to worry about it ;)

Sean

 


4 people have this question

Any comments from GS support team?

 

Answer
Hey Davendra,

You are right, the modules are cached and used in reference for subsequent calls from those scripts and modules. Variables passing through modules are unique to the context of each event though, so they will not be shared between events running the same module at the same time.
So, you dont need to worry about it ;)

Sean

 


1 person likes this
Login to post a comment