So I've been doing some memory testing by creating in Matlab two arrays as follows...
I = single( rand( 1200 , 1600 ) );
T = single( rand( 100 , 100 ) );
I then put my function in a loop with a printing of memory usage to a text file and clearing the returned libpointer.
for i = 1:10000
lp = calllib('IPPInterface', 'myFunc', I , T , size(I,2) , size(I,1) , size(T,2) , size(T,1) );
clear lp;
[u,s] = memory;
fprintf( fileID ,'%13g %13s\n' , u.MemUsedMATLAB , s.SystemMemory.Available );
end
Going that route definitely fills up my physical memory as you can see below, and has convinced me that what I was doing was a bad idea and Matlab does not handle this in some automated garbage collection like fashion for you.
>> memory
Maximum possible array: 38799 MB (4.068e+010 bytes) *
Memory available for all arrays: 38799 MB (4.068e+010 bytes) *
Memory used by MATLAB: 21393 MB (2.243e+010 bytes)
Physical Memory (RAM): 34814 MB (3.650e+010 bytes)
* Limited by System Memory (physical + swap file) available.
>> clear all
>> memory
Maximum possible array: 38803 MB (4.069e+010 bytes) *
Memory available for all arrays: 38803 MB (4.069e+010 bytes) *
Memory used by MATLAB: 21388 MB (2.243e+010 bytes)
Physical Memory (RAM): 34814 MB (3.650e+010 bytes)
* Limited by System Memory (physical + swap file) available.
>>


If I close Matlab than the OS naturally reclaims all that memory.

After digging around Matlab's website I did find a close enough example whereby the example had dynamically allocated a c-struct in a shared library, and where later on Matlab had to call a function written in that same library whose sole task was to delete that struct.
Working with Pointer Arguments; Multilevel Pointers
This example is right on, after implementing a simple interface call to the shared lib to deallocate my array and using it after I was done
void deallocateArray( float* A )
{
delete[] A;
}
The memory profile is flat, and the entire 10000 iterations complete much more rapidly...
for i = 1:10000
lp = calllib('IPPInterface', 'myFunc', I , T , size(I,2) , size(I,1) , size(T,2) , size(T,1) );
calllib('IPPInterface', 'deallocateArray', lp );
clear lp;
[u,s] = memory;
fprintf( fileID ,'%13g %13s\n' , u.MemUsedMATLAB , s.SystemMemory.Available );
end
