Which is more better when I destroy a object?

I usually initialize some objects:

Dim swApp as SldWorks.SldWorks

Dim swModel as SldWorks.ModelDoc2

Dim swPart as SldWorks.PartDoc

set swApp=Application.SldWorks

set swModel=swApp.ActiveDoc

set swPart =swModel as SldWorks.PartDoc

When Macro finish, I destroy these objects.

set swApp=nothing

set swModel=nothing

set swPart=nothing

If I only destroy swApp object, can swModel and swPart  release resource?

set swApp=nothing

SolidworksApi/macros
Comments 8
DY
DY 2021-03-26

Thanks a lot. I know your ideas.

DG
DG 2021-03-26

Classes self-terminate if there are no pointers to parent class.

When I create new classes I have "terminate" subrouitine in them where I set me.parent = nothing

DY
DY 2021-03-26

I want to understand the questions about memory release.

In .net, .net can collect garbage. In c++, garbage must be collected manually. I don't know how the macro to do .

DY
DY 2021-03-26

OK, I have tried it .

It means that every object must destroy with nothing one by one. if you dont do it , the application will waste lots of memory.

If macro finished, the memory of all objects that used in macro can release ? I can't get a way to test it.

I think the memory can release and solidworks will do this works. right or not?

thanks.

JB
JB 2021-03-26

Again.  Try it yourself.  This is an easy thing to do, and you learn more by trying things and reasoning them out for yourself.  Create swApp and swModel.  Destroy swApp.  See if swModel still works or if it is Nothing.

DG
DG 2021-03-26

There is no "new" so I guess it will work because they are all just pointers.

DY
DY 2021-03-26

I means ,

swModel is from swApp  and swPart is from swModel.

So, if I destroy swApp, swModel and swPart will be destroyed automatically?

thanks.

JB
JB 2021-03-26

Try it yourself... Destroy swApp and see if swModel still works.