Attend XDA's Second Annual Developer Conference, XDA:DevCon 2014!
5,813,360 Members 49,680 Now Online
XDA Developers Android and Mobile Development Forum

Global variable make app or game slow ?

Tip us?
 
indietab
Old
#1  
Junior Member - OP
Thanks Meter 0
Posts: 1
Join Date: Jul 2014
Post Global variable make app or game slow ?

HI
there as you can see the title what i am looking for

Global variable make app or game slow ?
Thanks
 
Hvedrung
Old
#2  
Hvedrung's Avatar
Junior Member
Thanks Meter 2
Posts: 8
Join Date: Jul 2013
Location: Brussels
No.
I don't know why it should. Using many global variable is not a good practice, you should avoid it but it shouldn't slow your app/game.
 
Angelkom
Old
#3  
Angelkom's Avatar
Member
Thanks Meter 34
Posts: 99
Join Date: Jan 2013
Location: Struga
Quote:
Originally Posted by indietab View Post
HI
there as you can see the title what i am looking for

Global variable make app or game slow ?
Thanks
Yes they slow it because the global variables cannot be collected with the garbage collector, so the app or game becomes heavy.
 
khashayarp
Old
#4  
Junior Member
Thanks Meter 0
Posts: 12
Join Date: Aug 2014
The primary reason why global variables are discouraged in javascript is because, in javascript all code share a single global namespace, also javascript has implied global variables ie. variables which are not explicitly declared in local scope are automatically added to global namespace. Relying too much on global variables can result in collisions between various scripts on the same page. It is better to avoid them.
 
gegerhr
Old
#5  
Junior Member
Thanks Meter 0
Posts: 7
Join Date: Jul 2014
Quote:
Originally Posted by indietab View Post
HI
there as you can see the title what i am looking for

Global variable make app or game slow ?
Thanks
You should run test to see usage of your memory, to many globals with lots of data can slow you down. You should use it for constatnts.
Keep the memory optimal, and make sure you dont have any memory leaks.

Important, you need way to see memory usage.
 
Edwin Bos
Old
#6  
Junior Member
Thanks Meter 1
Posts: 17
Join Date: Sep 2014
In short: no

However, you should avoid having large variables arrays, lists, etc. that you do not use. As the global variables will always have a reference to them, the garbage collector doesn't destroy them (as mentioned before), so they keep occupying memory unless you clear them yourself (for example by setting them to null).

If you need the functionality (and the values contained in the variables), it doesn't really matter where you define them, just know that you have to delete them (variableRef = null) if you dont need them anymore...

Have fun.
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


MediaTek Continues Steps Towards Being Developer-Friendly

Not too long ago MediaTek was very closed off towards the mobile developer … more

Sony PS4 Remote Play Ported to All Android Devices

Im pretty sure that every informed gamer out there perked their ears up when Sony came out … more

Change Your Samsung Galaxy S2’s Dialer Background in Real Time

As with anything, if youve looked at something long enough, things can … more