An attempt to implement NSAutoreleasepool from Objective-C and Cocoa into the pure C programming language
Never ever memory leaks again! No more free(z)ing stuff your programs! Easy to use!
If you did not get it already, i wrote an extension (2 files) for the programming language C which tries to implement Objective-C/Apple's/Cocoa's NSAutoreleasePool. This is very unfinished yet and many heap-allocating functions are not implemented and "hooked" yet. But it is just a matter of minutes as the whole stuff around is already there :). Also (this is the more serious problem) you can only have one autoreleasepool at one time, which means you will have to be careful to not encapsulate them or you will get some strange behaviours (for now, everything is pushed into the first of the encapsulated pools).How to implement
Implementing gc_autoreleasepools is not very hard. You either create them manually, which is NOT advised at all, or you do it the Apple-way. This is also the way i thought first at and the other one may not be possible to go with anymore in future versions. So to create one, just write:#include "C-Autoreleasepool.h"
...
gc_autoreleasepool(
your-code-goes-here;
and-here;
and-here...;
)
Now every object which is being allocated on the heap by malloc,... will be freed at the end of the block at the closing bracket. To make this work, you will OF COURSE need to include the header file C-Autoreleasepool.h and compile and link against C-Autoreleasepool.c. If you look at the header very close (very, very close) you will recognize the other, manual option. I have never tested, but calling gc_start_autoreleasepool() at the start and gc_end_autoreleasepool() at the end of your heap-allocating block should do exactly the same as of Version 0.10. As said, this is unadvised and may change soon.
To download the two framework files and some testing-and demo files, head over to my Github or just click here for the C-Autoreleasepool framework on Github by BannerBomb.