How does the JS API work in the backend? (memory management)
D
Davendra Jayasingam
started a topic
almost 6 years ago
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
C
Customer Support
said
over 3 years ago
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 ;)
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 ;)
Davendra Jayasingam
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:And my Event that requires my module looks like this.
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.
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
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstDavendra Jayasingam
Customer Support
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
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics