Do I have to call release() on matlab COM-interfaces?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Florian Berzsenyi
le 17 Déc 2021
Réponse apportée : Ishaan Mehta
le 12 Fév 2024
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) % ? ? ? ?
0 commentaires
Réponse acceptée
Ishaan Mehta
le 12 Fév 2024
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.
Save and Delete COM Objects: https://www.mathworks.com/help/matlab/matlab_external/saving-your-work.html#:~:text=server%20or%20control.-,Note,-In%20versions%20of
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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Use COM Objects in MATLAB dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!