Some FDO functions (for example, the Create methods) allocate memory when they are called. This memory needs to be freed to prevent memory leaks. All destructors on FDO classes are protected, so you must call a Release() function to destroy them (thus freeing their allocated memory). Each class inherits from the GisIDisposable class, which defines the AddRef() and Release() functions.
In addition, these classes are reference counted, and the count is increased when you retrieve them through a Get function. After finishing with the object, you need to release it (just as with COM objects). The object is destroyed only when the reference count hits 0. For example:
FdoFeatureClass* pBase = myClass->GetBaseClass();
...
// Must release reference added by GetBaseClass when done.
GIS_SAFE_RELEASE(pBase);
If the “*ptr” argument is not null, GIS_SAFE_RELEASE calls the release() method of the object pointed to by the “*ptr” argument.
A GisPtr smart pointer is provided to help manage memory. You wrap an FDO object in a GisPtr. The object is then released automatically when the GisPtr goes out of scope. The following code illustrates how to use GisPtr:
GisPtr<FdoFeatureClass> pBase = myClass->GetBaseClass();
...
// No need to release. Automatically happens when pBase
// is destroyed.