Archived Forum Post

Index of archived forum posts

Question:

Releasing objects and reference counts

Apr 10 '13 at 10:03

When doing the following:

ckCert * pCert = CkCertStore_FindCertBySubject(certStore,"Chilkat Software, Inc.");

success = CkSocket_InitSslServer(listenSslSocket,pCert);

Is it necessary to "dispose" pCert when done with it? Or does the CkSocket now own it and will dispose pCert for me?

Do ChilKat objects have reference counts with AddRef/Release like methods?

Signed 'Dazed and Confused'


Answer

The code snippet you provided above is incorrect. In the Chilkat "C" API, C++ objects (such as "CkCert") are not used. The "C" function you mentioned actually looks like this:

HCkCert CkCertStore_FindCertBySubject(HCkCertStore cHandle, const char *subject)

The "C" language does not use object. Therefore, the object-oriented API uses handles to opaque objects. Any handle returned from a Chilkat "C" function, such as an HCkCert, must be disposed by using the corresponding dispose function for that object. For example:

HCkCert hCert = CkCertStore_FindCertBySubject(certStore,"Chilkat Software, Inc.");
...
CkCert_Dispose(hCert);


Answer

The code snippet I provided comes from the sample code

http://www.example-code.com/vcpp/ssl_server.asp

The sample code does not dispose the cert object.