[fpc-pascal] TStringList/pchar question
Michael Van Canneyt
michael at freepascal.org
Sun Jun 2 20:48:50 CEST 2019
On Sun, 2 Jun 2019, Ryan Joseph wrote:
> I just learned that pchar is not ref counted like I used to think so I’m curious why this code doesn’t fail. Shouldn’t this crash because I free TStringList and then access GetText?
You're first doing gettext and then freeing. So this is OK.
>
> strings := TStringList.Create;
> strings.LoadFromFile(vertexShaderPath);
> vertexShaderSource := strings.GetText;
> strings.Free;
> glShaderSource(vertexShaderID, 1, @vertexShaderSource, nil);
You'll get a memory leak, unless you're freeing vertexShaderSource further
on.
See also
https://www.freepascal.org/docs-html/rtl/classes/tstrings.gettext.html
Michael.
More information about the fpc-pascal
mailing list