HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Do local array variables leak memory?

03-16-2004, 10:36 AM#1
AlexisMachine
Does anyone know if local arrays of primitive types (integers, booleans) are deallocated when a function returns?
03-16-2004, 01:50 PM#2
Narwanza
I doubt they would need to be, but they don't leak.
03-16-2004, 02:45 PM#3
Cubasis
Quote:
Originally Posted by Narwanza
I doubt they would need to be, but they don't leak.

Narwanza, if the arrays aren't de-allocated....then they most likely leak. It's as simple as that.

I'll do tests on this when I come home and write my results here. I do doubt that it leaks, as wc3's array system is dynamic and very smart. Each Array is only like 23 kbytes or sumtin If I remember right from some tests AIAndy (if I remember right) made.

Cubasis
03-16-2004, 07:21 PM#4
Cubasis
Ok - CONFIRMED

I ran a function that put a integer into element: 0, 1000, 2000, 3000, 4000 and 5000 (for fun) - 928000 times... That is, I created 928000 arrays, and it didn't leak a single thing (all memory-usage difference was way between margin of error (85.628 kb before, 86.027 kb after) which likely came from me typing a chat string, starting a event and/or some trigger-execution/reference count changing.

So no, local arrays don't leak.

Cubasis
03-16-2004, 10:37 PM#5
jmoritz
23 kbyte hmm. That's exactly 8192 times 4 :)
03-16-2004, 10:52 PM#6
Narwanza
I was refering to the types he was using as examples, booleans and integer. Now location array may have leaked, or just a plain array may have leaked, but i was reffering to booleans and integers.
03-17-2004, 08:03 AM#7
Cubasis
Quote:
Originally Posted by Narwanza
I was refering to the types he was using as examples, booleans and integer. Now location array may have leaked, or just a plain array may have leaked, but i was reffering to booleans and integers.

Hmm, Simple-type arrays are no different from handle-type arrays. Handles are just 32 bit integers, just like the integers, reals and booleans. Thus we talk about "all" types being a integer. So while the simple types use this 32-bit integer to store their value. Handle types use this 32-bit integer as a address to their entry in handle-array. And the string type uses this 32-bit integer as a index to a string-array. So again, there is no difference between a simple-type array and a handle array. They are both just something that keeps track of up to 8192 other normal variables.

Cubasis
03-25-2004, 08:38 PM#8
Alfryd
'Course, I'd say that if you declared a local trigger array, say, you will need to call DestroyTrigger() on anything you don't need afterwards.
03-26-2004, 02:05 PM#9
Vexorian
Quote:
Originally Posted by Cubasis40
Ok - CONFIRMED

I ran a function that put a integer into element: 0, 1000, 2000, 3000, 4000 and 5000 (for fun) - 928000 times... That is, I created 928000 arrays, and it didn't leak a single thing (all memory-usage difference was way between margin of error (85.628 kb before, 86.027 kb after) which likely came from me typing a chat string, starting a event and/or some trigger-execution/reference count changing.

So no, local arrays don't leak.

Cubasis
I would asume that local handle arrays still need to be set to null right?
03-26-2004, 02:36 PM#10
Cubasis
Alfryd: That's what I ment with this

Quote:
So again, there is no difference between a simple-type array and a handle array. They are both just something that keeps track of up to 8192 other normal variables.

So as Arrays are just comparable to 8192 normal variables, they thus indeed need to get de-referenced like other local variables. But ofcourse only the elements you actually used/set-to-a-handle.

And thus, yes to Lord Vexorian too.

Cubasis