Failure to release memory when releasing java objects
이전 댓글 표시
(EDITTED... PLEASE SEE COMMENT FOR UPDATED QUESTION)
I have a couple of java .jars that I am using to control a camera and framegrabber in a test setup. They work correctly in that I can get the data I need, and when I release the relevant java objects (in matlab), the hardware become available for use by other code.
Unfortunately, the largest contiguous memory block available after release drops from ~1300MB before getting the main object instance to ~500MB after releasing the object. If I continue to connect and release, this decreases further (although by a much smaller margin).
Even if I clear all variables (or even explicitly 'clear all' or 'clear classes') the memory remains discontiguous. The only way I know to fix it is to quit/restart matlab, and that isn't a good option, because I want other processing to be automatically performed after data acquisition occurs.
Is there something I could be doing in matlab that would cause this, or is it something I need to take up with the developers of the .jar/.dll files?
Below is a segment of the method-code for the matlab object I am using:
%(Camera) function call
%This function is used to create the initial camera object and
%initialize all the connections needed to the CCU and framegrabber.
function obj = Camera(IPAddress) %IPAddress should be a string
import nca.io.*;
obj.camobj = CNCACamera(IPAddress);
if ~obj.camobj.isReady
error(strcat('Problem connecting to CCU @ ',IPAddress, ': Not Ready'))
end
import ksi.jace.AVIO.AVIO;
import ksi.jace.IAVIO.IAVIOBoard;
import ksi.jace.IAVIO.IAVIOBoardFactory;
import ksi.jace.IAVIO.IAVIOInputStream;
obj.AVIOAInstance = AVIO.getInstance();
obj.AVIOBBoard = obj.AVIOAInstance.getBoard(0,1);
obj.AVIOCStream = obj.AVIOBBoard.GetInputStream();
obj.AVIODSource = obj.AVIOCStream.GetInputStreamSources();
obj.AVIOCStream.SetInputStreamSource(obj.AVIODSource(3));
%Communicate with CCU and get type/SW/etc?
end
%(Release) function call
%This function releases the hardware for future use.
function Release(obj)
obj.AVIODSource(4).Release();
obj.AVIODSource(3).Release();
obj.AVIODSource(2).Release();
obj.AVIODSource(1).Release();
obj.AVIOCStream.Release();
obj.AVIOBBoard.Release();
obj.AVIOAInstance.destroyBoard(obj.AVIOBBoard);
obj.camobj.uninit;
clear obj
end
Thanks in advance for any/all help.
채택된 답변
추가 답변 (1개)
Malcolm Lidierth
2011년 10월 2일
0 개 추천
clear obj in the Release function serves no useful purpose - it only clears the local copy of obj in the scope of that function.
"clear all" would clear the base and the function workspace - but not that of the function calling Release.
Try "clear all" at the command prompt once everything is closed.
If the jar is on the dynamic path,try "clear java" at the command prompt and look for warnings
카테고리
도움말 센터 및 File Exchange에서 Java Package Integration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!