If I create a .NET object instance, then that instance is never garbage collected, even if I call "clear all"

4 件のコメント

Guillaume
Guillaume 2020 年 1 月 8 日
Can you provide a bit more details, such as example code and how you ascertain the object is not destroyed?
Guillaume
Guillaume 2020 年 1 月 8 日
Roberto Olmi's comment mistakenly posted as an answer moved here:
Constructor of base class (retains a reference to a "Layout" object):
Here the test code in Matlab:
At the end, by looking with a memory profiling tool I can see that Matlab application retains 4 instances of "Layout" and 4 instances of "RoadmapHelper"
Roberto Olmi
Roberto Olmi 2020 年 1 月 8 日
I increased the for iterations above to
for i=1:100
this is the result as seen by the memory profiler application:
Capture.PNG
Capture.PNG
Guillaume
Guillaume 2020 年 1 月 8 日
The delete calls should have released all the references that matlab holds to your objects. The garbage collection itself is handled by .Net itself. Could it be that your LayoutLoader keeps hold of references to the objects?

サインインしてコメントする。

 採用された回答

Roberto Olmi
Roberto Olmi 2020 年 1 月 8 日

0 投票

Dear Guillaume,
thanks a lot for you help. I understood that my objects couldn't be collected because they were used inside a separated thread that was never stopped after object creation.
Stopping that thread before calling delete allows the object to be garbage ollected.
Thanks again
Roberto

その他の回答 (0 件)

カテゴリ

製品

リリース

R2019b

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by