And now the question: what will happen to result object in function GetStringList:Tstringlist, which is created, but never freed? (I call 2 times Create and only 1 time Free) Is it memory safe to provide objects by function or should I use procedures to do this task, where object creation and destroying is simply handled (procedure ProvideStringlist)? I call 2 times Create and 2 times Free. Or is there another solution?
Thanx in advance
( 5 months ago )
I don't know what you mean by safe, but it is common practice. The caller of the function becomes responsible for freeing the returned object:
s : TStringList;begin
s := GetStringList;// stuff