HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How do I declare a local unit array?

02-05-2007, 12:24 AM#1
CaptainPicard
Is it possible?

I suppose it'd be easy enough to use a global array...

Also, how would I prevent memory leaks?

Thanks!

Capt. Picard
02-05-2007, 12:27 AM#2
Mezzer
Collapse JASS:
function whatever takes nothing returns nothing
local unit array YourUnitArray
endfunction

Prevent which memory leaks exactly? If you mean regarding the array, then you wouldn't have to worry, the array itself effectively only points to existing units, so you don't need to worry about it leaking anything.

Here's a couple of tutorials on the subject in general.
http://www.wc3campaigns.net/showthread.php?t=55022
http://www.wc3campaigns.net/showthread.php?t=80072
02-05-2007, 12:35 AM#3
CaptainPicard
Very nice! Thanks!

I think I'll still have to set

Collapse JASS:
set YourUnitArray = null

at the end of the function to prevent the small handle memory leak, no?
02-05-2007, 12:39 AM#4
Mezzer
Honestly, not sure. I don't think so though. You could do so just in case, but I' pretty sure that even if it leaked it wouldn't be much of one.
02-05-2007, 12:44 AM#5
wyrmlord
I'm pretty sure you can't null an entire array at once. I don't know if you need to null it, but if you want to you'd probably have to null it 1 part at a time.
02-05-2007, 12:56 AM#6
Vexorian
When a function scope ends, the array reference counts are automatically decreased. aka you don't need to null array indexes


Edit: pipedream claims the opposite, so you better null stuff.

Most of the times, you don't really need a local array and a global one works better...