This simulates memory management in C, when we want to create or use an object, then the object will call the Retain method, Count +1, when we want to release the object, we will call free, note here to judge the counting memory, if it is 0, then destroy.
#import <Foundation/Foundation.h>
int cnt = 0;
void Fun (Charchar * p)
{
printf ("%c\n", P[0]);
Charchar * RETAIN1 (Charchar * p)
{
//retain (p);
CNT + +;
return p;
}
void Dealloc1 (Charchar *p)
{free
(p);
}
void Release (Charchar * p)
{
cnt--;
if (cnt = = 0) {
//free (p);
Dealloc1 (P);
}
int main (int argc, const CHARCHAR * argv[])
{
@autoreleasepool {
Charchar * p = (Charchar *) malloc (1000);
p[0] = ' a ';
P[1] = ' B ';
Charchar * q = p;
Early release of
//free (p);
printf ("%c\n", P[0]);
Free (q);
Free (q);
}
return 0;
}
The above is the simulation C language memory management of the implementation code, I hope to help you learn.