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.
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/
  • The Helper The Helper:
    Here is another comfort food favorite - Million Dollar Casserole - https://www.thehelper.net/threads/recipe-million-dollar-casserole.193614/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top