Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to properly free records that contain various types in Delphi at once?
    primarykey
    data
    text
    <pre><code>type TSomeRecord = Record field1: integer; field2: string; field3: boolean; End; var SomeRecord: TSomeRecord; SomeRecAr: array of TSomeRecord; </code></pre> <p>This is the most basic example of what I have and since I want to reuse <code>SomeRecord</code> (with certain fields remaining empty, without freeing everything some fields would be carried over when I'm reusing <code>SomeRecord</code>, which is obviously undesired) I am looking for a way to free all of the fields at once. I've started out with <code>string[255]</code> and used <code>ZeroMemory()</code>, which was fine until it started leaking memory, that was because I switched to <code>string</code>. I still lack the knowledge to get why, but it appears to be related to it being dynamic. I am using dynamic arrays as well, so I assume that trying <code>ZeroMemory()</code> on anything dynamic would result in leaks. One day wasted figuring that out. I think I solved this by using <code>Finalize()</code> on <code>SomeRecord</code> or <code>SomeRecAr</code> before <code>ZeroMemory()</code>, but I'm not sure if this is the proper approach or just me being stupid.</p> <p>So the question is: how to free everything at once? does some single procedure exist at all for this that I'm not aware of?</p> <p>On a different note, alternatively I would be open to suggestions how to implement these records differently to begin with, so I don't need to make complicated attempts at freeing stuff. I've looked into creating records with <code>New()</code> and then getting rid of it <code>Dispose()</code>, but I have no idea what it means when a variable after a call to <code>Dispose()</code> is undefined, instead of nil. In addition, I don't know what's the difference between a variable of a certain type (<code>SomeRecord: TSomeRecord</code>) versus a variable pointing to a type (<code>SomeRecord: ^TSomeRecord</code>). I'm looking into the above issues at the moment, unless someone can explain it quickly, it might take some time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload