How to release memory on the code

The problem is when i read component‘s customInfo,i need to use  GetModeDoc2(). if the function return null,i need to open the file.But if the file have too many component,the memory will broken down .So Is there have anyway to release memory?I try to use modelDoc2.close() and Swapp.closeDoc("**").they have do nothing.I see the documentManager but i haven't the lisence.

SolidworksApi/macros