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
Thanks a lot. I know your ideas.
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
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 .
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.
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.
There is no "new" so I guess it will work because they are all just pointers.
I means ,
swModel is from swApp and swPart is from swModel.
So, if I destroy swApp, swModel and swPart will be destroyed automatically?
thanks.
Try it yourself... Destroy swApp and see if swModel still works.