Archived Forum Post

Index of archived forum posts


Dispose of "C" Handle returned by API?

Apr 29 '13 at 08:46

I have a question regarding the usage of the C Libraries:

In which cases do I have to explicitly dispose a Chilkat object? My current example are the ZIP Libs, but the basic question matters for the whole library:

CkZipEntry_Dispose states:

Objects created by calling CkZipEntry_Create must be freed by calling this method.

How is this to be treated with objects handles returned by the API itself, for example with CkZip_FirstEntry?

I assume that I get some reference to an existing object within the ZIP Object in question. So on one hand I assume, that I must not dispose it. This would be in accordance with the documentation, since I did not explicitly create the data structure in question.

However, I believe that I am experiencing a memory leak at exactly that call, which vanishes if I add a CkZipEntry_Dispose after getting and using the FirstEntry handle.


Any object handle returned by a Chilkat "C" function must also be explicitly freed by the application by calling the appropriate "_Dispose" function.

For example:

    //  Get the number of files and directories in the .zip
    n = CkZip_getNumEntries(zip);

for (i = 0; i <= n - 1; i++) {

    entry = CkZip_GetEntryByIndex(zip,i);
    if (CkZipEntry_getIsDirectory(entry) == FALSE) {