ZFFramework
Loading...
Searching...
No Matches
Macros | Functions
ZFObjectRetain.h File Reference

retain count logic for ZFFramework More...

#include "ZFObjectCore.h"

Go to the source code of this file.

Macros

#define zfAlloc(T_ZFObject, ...)
 alloc an object, see ZFObject
 
#define zfunsafe_zfAlloc(T_ZFObject, ...)
 no lock version of zfAlloc, use with caution
 
#define zfRetain(obj)
 retain an object, see ZFObject
 
#define zfunsafe_zfRetain(obj)
 no lock version of zfRetain, use with caution
 
#define zfRelease(obj)
 release an object, see ZFObject
 
#define zfunsafe_zfRelease(obj)
 no lock version of zfRelease, use with caution
 
#define ZFALLOC_CACHE_RELEASE(action)
 mark class that it should apply cache logic when alloc
 
#define ZFALLOC_CACHE_RELEASE_ABSTRACT(action)
 ZFALLOC_CACHE_RELEASE for abstract class
 
#define zfRetainChange(property, propertyValue)
 util to release property's old value, retain new value, then set to property
 
#define zfunsafe_zfRetainChange(property, propertyValue)
 no lock version of zfRetainChange, use with caution
 

Functions

void zfAllocCacheRemoveAll (void)
 remove all object cache, see ZFALLOC_CACHE_RELEASE
 

Detailed Description

retain count logic for ZFFramework

Macro Definition Documentation

◆ zfAlloc

#define zfAlloc ( T_ZFObject,
... )

alloc an object, see ZFObject

if your class has declared ZFALLOC_CACHE_RELEASE, then zfAlloc would automatically has cache logic

◆ ZFALLOC_CACHE_RELEASE

#define ZFALLOC_CACHE_RELEASE ( action)

mark class that it should apply cache logic when alloc

usage:

zfclass YourObject : zfextend SomeParent {
ZFOBJECT_DECLARE(YourObject, SomeParent)
cache->yourCacheCleanupAction();
})
};
#define zfextend
dummy macro shows class inherit from another
Definition ZFCoreTypeDef_ClassType.h:53
#define zfclass
same as class, shows that this class is a ZFObject type
Definition ZFObjectClassTypeFwd.h:38
#define ZFOBJECT_DECLARE(ChildClass, SuperClass,...)
necessary for every class inherit from ZFObject
Definition ZFObjectDeclare.h:126
#define ZFALLOC_CACHE_RELEASE(action)
mark class that it should apply cache logic when alloc
Definition ZFObjectRetain.h:178

once declared, when you alloc object with no extra param, the cache logic would automatically take effect:

ZFObject *obj = zfAlloc(YourObject); // first time alloc
zfRelease(obj); // release, and the object would be cached
obj = zfAlloc(YourObject); // second time alloc, the previously cached object would be returned
zfRelease(obj);
obj = zfAlloc(YourObject, someParam); // alloc with extra param, no cache logic would be applied
zfRelease(obj);
#define zfRelease(obj)
release an object, see ZFObject
Definition ZFObjectRetain.h:140
#define zfAlloc(T_ZFObject,...)
alloc an object, see ZFObject
Definition ZFObjectRetain.h:96
base class of all objects
Definition ZFObjectCore.h:209

note the alloc cache logic is explicitly attached to class, parent class' ZFALLOC_CACHE_RELEASE does not make child class cacheable, the child class must also explicitly declare ZFALLOC_CACHE_RELEASE to enable cache logic

◆ zfRetainChange

#define zfRetainChange ( property,
propertyValue )

util to release property's old value, retain new value, then set to property

this macro is similar to the retain property in Object-C
typical usage:

ZFObject *property = ...;
ZFObject *newProperty = ...;
// OK, release property, retain newProperty, then set to property
zfRetainChange(property, newProperty);
// OK, use return value of a function as new value
// but keep it in mind, that the new value will be retained
zfRetainChange(property, funcThatReturnZFObject());
// OK, same as release old property and set it to zfnull
// error, new value must be ZFObject
// zfRetainChange(property, 123);
// error, property must be a variable contains a (ZFObject *)
// zfRetainChange(zfnull, newProperty);
// zfRetainChange(funcThatReturnZFObject(), newProperty);
#define zfnull
same as NULL, defined for future use
Definition ZFCoreTypeDef_CoreType.h:50
#define zfRetainChange(property, propertyValue)
util to release property's old value, retain new value, then set to property
Definition ZFObjectRetain.h:313
See also
zfRetain, zfRelease, ZFPROPERTY_RETAIN