Implementation of Cache Memory Allocation

Hi, I wonder how torch implements the cache memory allocation.

Or is there any example that can show us when and how torch releases memory?