cancel
Showing results for 
Search instead for 
Did you mean: 

Dispose of SDK UI API Objects

Former Member
0 Kudos

Is it recommended to dispose the UI objects like this? Is there a check by sap on the refcount of the ui com objects?

System.Runtime.InteropServices.Marshal.ReleaseComObject( m_menu );

I know it is strongly recommended for DI objects and had already some trouble with it. Strange enough none of the sample code releases the objects witch is wrong in my opinion!

What is yours expirience with the UI objects? Do i have to dispose the after use?

Accepted Solutions (1)

Accepted Solutions (1)

Gianluigi
Product and Topic Expert
Product and Topic Expert
0 Kudos

Why should you dispose explicitily UI objects ? .NET garbage collection should

do it for you ....

Former Member
0 Kudos

If you add a user fields with UserFieldMD and do not release the object explicit you get the error refcount not zero.

The objects self checks if an other object already exists to to avoid conflicts. You also dont know when the garbage collector will destroy the first object. So running the code again before the GC has run throws an error.

Thats why I whant to know if this is also the case for UI objects.

Former Member
0 Kudos

Hi Maarten,

It really depends on how you've designed your program. Every time a form is closed I have code which explicity destroys the form object and calls the garbage collector. This way I know the memory is more or less immediately released when the form is closed. But as I mentioned before, it depends on how you've structured your program and if you want to be in control of freeing memory etc...

Lita

Gianluigi
Product and Topic Expert
Product and Topic Expert
0 Kudos

The only objects that are required to be explicitily disposed are the DI metadata

objects. UI objects (and all the other DI objects) are not. So basically it is up to

your design choices whether you dispose them or not.

Former Member
0 Kudos

Hi,

What kind of DI objects represent metadata??

Regards.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Maarten Jardin ,

I think we need not want to destroy UI Components. In fact better avoid.

When we create a DI object lets say a company object a new object will be loaded into the memory of your add-on and only your add can able to access these objects.

Where as in UI we are not creating any UI component. We are manipulating with SBO UI API to load components. You are just referring to the UI components loaded by SAP Business One.

When we see this in depth, lets assume we are creating an add-on that loads UI and DI object. After you close your add on still you form will be live inside SAP Business One. Now you access these form using addition add-on and manipulate with it.

Any thoughts by others?

Regards

B.Ravi Shankar