Take the following code:
In the Add method, you can see that I an constucting a Local Line from the parameters passed in and then adding this to the list.
It DOES seem to work, but if the garbage collector got hold of the local variable once the function was finished, could it free up the Local Line variable and thus the list would be pointing to a Null variable? Or won't the garbage cleaner clean it because it knows the list is using it, and then when the list is finally freed, it will clean up all the Local Line variables that were made. Is this how it works?
Perhaps there is a better way. Any comments? Thanks.
Type TIniLine Field Name$ Field Value$ End Type Type TIniFile Extends TList Field FileName$ 'full filepath (or relative path) Method Add(name$,value$) Local Line:TIniLine = New TIniLine Line.Name = name Line.Value = value Super.AddLast(Line) End Method Method Save() Local file:TStream=WriteFile(FileName) If Not file RuntimeError("Failed to open file "+FileName) Local Line:TIniLine 'Create a file, overwriting any that already exists For Line = EachIn Self WriteLine file,Line.Name+"="+Line.Value Next CloseStream file End Method End Type
In the Add method, you can see that I an constucting a Local Line from the parameters passed in and then adding this to the list.
It DOES seem to work, but if the garbage collector got hold of the local variable once the function was finished, could it free up the Local Line variable and thus the list would be pointing to a Null variable? Or won't the garbage cleaner clean it because it knows the list is using it, and then when the list is finally freed, it will clean up all the Local Line variables that were made. Is this how it works?
Perhaps there is a better way. Any comments? Thanks.