필터 지우기
필터 지우기

Do I have to call release() on matlab COM-interfaces?

조회 수: 4 (최근 30일)
Florian Berzsenyi
Florian Berzsenyi 2021년 12월 17일
답변: Ishaan Mehta 2024년 2월 12일
Take a look at the following MATLAB example (copied from there), demonstrating collections:
hCollection = hControl.Plots;
for i = 1:hCollection.Count
hPlot = invoke(hCollection,'Item', i);
Redraw(hPlot)
release(hPlot);
end;
release(hCollection);
My simple question now is: Do I have to call relase on every COM-interface I generate, e.g. by calling invoke()? Currently I do not, as I thought that the MATLAB garbage collector takes care of reference counting and memory release.
Another example below might refine my question. When will the interface "Sheets" be allocated, and not just referenced?
newWBook = xlApp.Sheets.Open(*name*)
% vs.
wBooks = xlApp.Sheets % or invoke(xlApp, 'Sheets')
newWBook = wBooks.Sheets
release(wBooks) % ? ? ? ?

채택된 답변

Ishaan Mehta
Ishaan Mehta 2024년 2월 12일
Hi Florian,
From the code snippets shared by you, I understand that you wish to check if "release" function in MATLAB mandatorily to release a COM interface.
I checked MathWorks documentation regarding the same, and it states that in MATLAB versions prior to 6.5, not manually releasing interface handles or not properly deleting the server could lead to memory leaks. This issue would occur even when the variable associated with the interface or COM object was allocated to something else. From MATLAB version 6.5 onwards, the system automatically disposes of the server and all related interfaces when the corresponding variable is either reassigned or goes out of scope, effectively preventing such memory leaks.
Nonetheless, if there is a need to promptly relinquish a COM object or interface and liberate all tied resources, invoking the "release" function on the COM object is a useful option. This action can be particularly beneficial in scenarios where numerous COM objects are in use or when the COM server is constrained by resource limitations.
Hope this helps!

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Use COM Objects in MATLAB에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by