wraithdu Posted May 8, 2009 Share Posted May 8, 2009 I'm curious how memory is handled for DllStructs and Arrays. For instance, in most windows API functions where a structure is used, the user must create the structure and pass the pointer to the function. The user is responsible for dealing with memory allocation and freeing. In user created functions the same idea applies. However in AutoIt it's a common practice (perhaps not a good one) to create local structures or arrays in a user function, then return the function or array. Now I thought AutoIt was supposed to destroy all local variables, including structures and arrays, when they go out of scope. So this technically shouldn't work. Is this the case? Or is AutoIt intelligently creating a copy of the array or structure when it is returned from a function, and freeing the original memory? Or does it not free the original memory only if it is returned? I ask because this could be a huge memory leak if the local arrays and structures are not destroyed when going out of scope (and not a return value), and the user does not manually free them ($struct or $array = 0). I'd like to get a better understanding of how AutoIt handles these memory allocations / deallocations to prevent such memory leaks. Thanks! Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 8, 2009 Share Posted May 8, 2009 It's kind of a reference thing. Since the return value creates another reference to the data, it isn't destroyed. Link to comment Share on other sites More sharing options...
WideBoyDixon Posted May 8, 2009 Share Posted May 8, 2009 So is there some sort of garbage collector that runs at the end of a script which frees up all the allocated memory? [center]Wide by name, Wide by nature and Wide by girth[u]Scripts[/u]{Hot Folders} {Screen Calipers} {Screen Crosshairs} {Cross-Process Subclassing} {GDI+ Clock} {ASCII Art Signatures}{Another GDI+ Clock} {Desktop Goldfish} {Game of Life} {3D Pie Chart} {Stock Tracker}[u]UDFs[/u]{_FileReplaceText} {_ArrayCompare} {_ToBase}~ My Scripts On Google Code ~[/center] Link to comment Share on other sites More sharing options...
Richard Robertson Posted May 8, 2009 Share Posted May 8, 2009 Sort of. Part of it is also that at the end of the program, Windows will try to free things that the program allocated locally. Link to comment Share on other sites More sharing options...
monoceres Posted May 8, 2009 Share Posted May 8, 2009 (edited) This is the beauty with using a language that using variants and dynamic memory allocation. You don't need to worry about how the memory is handled. I actually think it's impossible to create pure memory leaks in autoit (calling dll's that allocates memory doesn't count) since if you loose the ability to access the variable autoit removes it.I'm only guessing here but it would be a fair guess that autoit store some kind of reference count for each dllstruct/array. Edited May 8, 2009 by monoceres Broken link? PM me and I'll send you the file! Link to comment Share on other sites More sharing options...
Valik Posted May 8, 2009 Share Posted May 8, 2009 Sort of.Part of it is also that at the end of the program, Windows will try to free things that the program allocated locally.Sort of not. AutoIt does not have a garbage collector. When an object is goes out of scope it's destroyed, full stop. There is no delayed/deferred/scheduled cleanup. A variable goes out of scope, it's gone. Return values are a special case, obviously.monoceres said it best. You don't need to worry about memory so stop worrying about it. I find it a little insulting that you think there is even potential we'd overlook such a glaring logic hole there. mLipok and TheDcoder 1 1 Link to comment Share on other sites More sharing options...
wraithdu Posted May 8, 2009 Author Share Posted May 8, 2009 (edited) Thanks everyone. @Valik I didn't mean to imply any sort of error on the part of the devs. I was referring to user created memory leaks. They're easy enough to create from bad code in other languages, so I wanted to be sure and avoid any coding practices in AutoIt that might leak. Edited May 8, 2009 by wraithdu Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now