ComApiBridge.State.ObjectFactory, need to release created objects? how?

ComApiBridge.State.ObjectFactory, need to release created objects? how?

alexisDVJML
Collaborator Collaborator
1,526 Views
4 Replies
Message 1 of 5

ComApiBridge.State.ObjectFactory, need to release created objects? how?

alexisDVJML
Collaborator
Collaborator

I just started to wonder how/if objects we create using any of the ObjectFactory method is correctly release?
Since we get an interface in return that is not an IDisposable, are these objects correctly tracked by the GC?
How to ensure we don't create memory links?

And/or if we want to release them earlier?

 

Should we call the (hidden) method nwInvalidate() ? only if nwOwn is true?

Worrying I actually missed such free operations since we use these ObjectFactory methods quite extensively!

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
1,527 Views
4 Replies
Replies (4)
Message 2 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @alexisDVJML ,

 

Which ObjectFactory are you referring to?
What are you using it for?
Could you please explain your issue in more detail?

 


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 3 of 5

alexisDVJML
Collaborator
Collaborator

Hi Naveen,

 

Thanks for getting back on this topic so quickly, strongly appreciated.

 

I'm mostly using 

ComApiBridge.State.ObjectFactory(nwEObjectType, null, null)

 

Here are the types I create with a quick explanation for each:

 

InwOaPropertyVec and InwOaProperty aka nwEObjectType.eObjectType_nwOaPropertyVec and nwEObjectType.eObjectType_nwOaProperty

for getting/setting a specific (or a set of specific) user-defined properties in a model item

 

InwLVec3f aka nwEObjectType.eObjectType_nwLVec3f

for creating RGB colors once and reusing them repeatedly in our Renderer plugin

InwLBox3f aka nwEObjectType.eObjectType_nwLBox3f

 for creating a boundingbox used for example to zoom the current view to a specific area with ComApiBridge.State.ZoomInCurViewOnBoundingBox

 

InwOaPath aka nwEObjectType.eObjectType_nwOaPath

to get an empty path that I fill one by one to match an existing ModelItem and directly go down its parents from top to check if they are partitions.

Aka to build a list of partitions of a specific modelItem from the root instead of using higher level Parent calls that are super slow

 

InwOpSelection aka nwEObjectType.eObjectType_nwOpSelection

to get an empty selection which I fill with Paths from model items and use to override transparency with ComApiBridge.State.OverrideTransparency

 

InwOpView aka nwEObjectType.eObjectType_nwOpView

to create a blank view and be able to set its ApplyHideAttribs and ApplyMaterialAttribs values

 

A few other types I just looked at but not used yet at least via ObjectFactory creation...

 

My guess/hope is these COM objects are cleared at some point when not used but I suddenly get a doubt since I can't fathom by which magic this would happen 😉
Also if something need to be done in my source code to "release" these, wondering if there is a generic mechanism or if it would depend on the object type?

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes
Message 4 of 5

naveen.kumar.t
Autodesk Support
Autodesk Support

Hi @alexisDVJML ,

 

Typically, COM objects are reference-counted, if I recall correctly. Therefore, it might be necessary for you to ensure you are managing that aspect properly. Regrettably, I'm not particularly well-versed in the intricacies of the COM API.


Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

0 Likes
Message 5 of 5

alexisDVJML
Collaborator
Collaborator

Hum, OK.
The thing is ObjectFactory returns only interface objects (or more exactly ObjectFactory return objects that we cast to an InwXXX).

These have the (hidden) method nwInvalidate(). Is it the method to count to invalidate/decrement the reference count?

Main Scientist, Full Stack Developer & When Time Permits Director of IDIGO ► On your marks, Set, Go
0 Likes