Galaxy Editor = No leaks right?

phyrex1an

Staff Member and irregular helper
Reaction score
447
Presumably there is a garbage collector embedded in the runtime. I think Natives.galaxy has some description of what types are garbage collected.

However, it's time to kill of the myth that Garbage Collector == No Leaks. That isn't true. A Garbage Collector determines what is garbage by checking what values are no longer reachable from the global environment. Depending on the algorithm there might be false negatives (stuff that isn't reachable but still isn't considered garbage), though if Blizzard was reasonable intelligent they didn't implement such an algorithm. However, if you for some reason forgets to remove a global reference to an object it will never be removed even if you'll never reference it again. Thus, we have a leak that no garbage collector in the world will be able to remove (unless we want to introduce false positives, an extreme evil).

For example, say that we have a garbage collected type A. Now we want to track all A's created by our code so we use a collection (an array in this case) to store each A created. Now when we no longer wants to use our A we must remove it from that collection (akin to how you had to RemoveLocation when we no longer wanted it) or else garbage collection will never take place.

tl;dr: A garbage collector only removes the obvious garbage, the non obvious ones you still have to fix yourself or else you'll leak memory.
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
//--------------------------------------------------------------------------------------------------
// About Types
//--------------------------------------------------------------------------------------------------
//
// -- Complex types and automatic deletion --
// 
// Many native types represent "complex" objects (i.e. larger than 4 bytes).  The script language
// automatically keeps track of these objects and deletes them from memory when they are no longer
// used (that is, when nothing in the script references them any longer).  The types which benefit
// from automatic deletion are:
//
//      abilcmd, bank, camerainfo, marker, order, playergroup, point,
//      region, soundlink, string, text, timer, transmissionsource, unitfilter, unitgroup, unitref,
//      waveinfo, wavetarget
//
// Other object types must be explicitly destroyed with the appropriate native function when you
// are done using them.

Source.
 

celerisk

When Zerg floweth, life is good
Reaction score
62
... say that we have a garbage collected type A. Now we want to track all A's created by our code so we use a collection (an array in this case) to store each A created. Now when we no longer wants to use our A we must remove it from that collection (akin to how you had to RemoveLocation when we no longer wanted it) or else garbage collection will never take place.

I would very much complain if it removed something I've still stored somewhere.
That's not a leak either in my book.
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
@ phyrex1an:
You will not leak memory since your global variables / arrays have a pre-defined size. You will however have to clean it up somehow because otherwise you will end up with code starting to act weird or even crash when that array is completely full.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
@ phyrex1an:
You will not leak memory since your global variables / arrays have a pre-defined size. You will however have to clean it up somehow because otherwise you will end up with code starting to act weird or even crash when that array is completely full.
I guess memory leaks never existed then since your computer has a pre-defined memory pool... Though, fair point. If you can't allocate new memory then memory leaks doesn't exists. But you can allocate new memory in sc2. The question is, can any of these data structures you create reference another data structure? In that case, garbage collection doesn't solve all your leaking problems. Besides, manual allocators (such as unit indexer) are also subjects to memory leaks as you say "You will however have to clean it up somehow".

I would very much complain if it removed something I've still stored somewhere.
Me too. Citing myself: "unless we want to introduce false positives, an extreme evil". Though it would be neat if a garbage collector could solve the halting problem and remove all memory that I will never use again automagically...

That's not a leak either in my book.
Well, perhaps I'm liberal in my definition but memory that hangs around that I no longer wants to use is a memory leak in my book. Some language designers agree with me though and introduces stuff like weak references and other kludges.
Edit: I hate to fall back on a appeal to authority but if we can't even agree on what a leak really is then there isn't much to be said about the subject...
 

celerisk

When Zerg floweth, life is good
Reaction score
62
if we can't even agree on what a leak really is then there isn't much to be said about the subject...

Weak attempt at a definition:
A leak happens when you lost the (last) reference to an object but the object is still around.

At least, that's what I'm working with.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
And my definition is: A leak happens when you'll never reference an object but the object is still around.

A reformulation could be this (I hope this will convince you that my definition is more useful :p): A memory leak happens when a piece of memory can be reclaimed without altering program behaviour (modulo time and space usage ofc) but isn't reclaimed.

Depending on context you might want to add an "eventually reclaimed" clause somewhere.
 

No_exit

Regular User (What is Custom User Title?)
Reaction score
40
@ phyrex1an:
Your definition is very strong but it has the disadvantage that the effect of a memory leak can anywhere between "not noticeable" and "crash". I'm pretty sure that the original post only cares about things that make his pc significantly slower or make it crash.

Also note that in practice "you'll never reference an object" is very hard, if not impossible to determine (equivalent to halting problem probably).

So to answer if there are any memory leaks that can cause your pc significantly or make it crash, do we all agree on the parts below?
- Global variable non-arrays are fine to use.
- Global variable Arrays are fine to use but you yourself are in charge to make sure that previously unused indexes of the array that are no longer used are recycled such that the array will not overfill.
- Local variables are fine to use as long as the function is not put in an infinite loop (with waits between them).
- If there are any variables which are circular (as in variables referring each other; for galaxy I think the only ones are structs) then you should dereference the links to each other until it is no longer circular and then the garbage collection can clean it up.

The only thing I think is possible for a memory leak is to have some sort of local function which allocates memory but is then put in an infinite long wait. This function needs to be called a lot then. But yeah, you deserved to have your memory eaten then.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
To sum it up for those that do not understand very much of programming:

You do not need to null your locals at the end of your functions anymore (memory leaks are gone), however, you should still destroy/remove the handle they were pointing to, in case it was a handle variable. The garbage collector solves some of those cases too, but is not able to solve all cases. You should not trust in the garbage collector, but program clean in the first place. For readability, its better anyways (and well ... it 'looks' better ... I've always been a perfectionist ;) ).

So, to express it with JASS terms: You need to DestroyGroup(), but you do not need to set group = null after that.
 

Jesus4Lyf

Good Idea™
Reaction score
397
So, to express it with JASS terms: You need to DestroyGroup(), but you do not need to set group = null after that.
What? Did no one read my post? There is no destroy group, it actually destroys the objects when you no longer need them, like Java or something else...
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
it actually destroys the objects when you no longer need them
Um no, that's the point. It actually destroys the objects when you no longer references them [from the global scope]. Memory leaks are still possible, just like in Java or something else.

Edit: Though, a destroy group equivalent isn't the solution... The solution is to make sure that you no longer reference stuff that you want garbage collected.
 

Zwiebelchen

You can change this now in User CP.
Reaction score
60
Um no, that's the point. It actually destroys the objects when you no longer references them [from the global scope]. Memory leaks are still possible, just like in Java or something else.

Edit: Though, a destroy group equivalent isn't the solution... The solution is to make sure that you no longer reference stuff that you want garbage collected.
So basicly its the exact opposite of what I said: Always null every handle variable properly, to make sure you kill the reference to the object. I didnt know that Galaxy doesnt have destroy funcs anymore. ... Weird. As if blizzard wants to force us to generate unclean code.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top