From the pickaxe:
You may sometimes need to allocate memory in an extension tha t won’t be used for object storage—perhaps you have a giant bitmap for a Bloom filter, an image, or a whole bunch of little structures that Ruby doesn’t use directly. To work correctly with the garbage collector, you should use the following memory allocation routines. These routines do a little bit more work than the st andard malloc function. For instance, if ALLOC_N determines that it cannot allocate the desired amount of mem ory, it will invoke the garbage collector to try to reclaim some space. It will raise a NoMemError if it can’t or if the requested amount of memory is invalid
But in a given function, I know exactly when release the memory. In this case, should I still using ALLOC_N
to alloc the memory?
Is there legitime cases when I should free the memory myself, or it is better always use ALLOC_N
and don't care about it?