cancel
Showing results for 
Search instead for 
Did you mean: 

when and how many times do i have to call the garbage collector ?

Former Member
0 Kudos

hi,

how often do i have to delete my objects ? Do i have to delete the objects within my sub like as follows or is it ok when i delete all object when my addon will exit?



private sub x()

        Dim oRec As SAPbobsCOM.Recordset
        oRec = moSBOCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

...

'delete objects
      System.Runtime.InteropServices.Marshal.ReleaseComObject(oRec)
        oRec = Nothing
        GC.Collect() 'Call the garbage collector for good measure
        GC.WaitForPendingFinalizers()

end sub

thanks

Markus

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Markus,

Technically I don't know the answer to your question, but it makes more sense to free resources and delete your objects as soon as you don't use them anymore, like you specified in your code below. Freeing only when you close the application might be difficult to manage and also means that most of your variables will have to be declared as global. Every time you instanciate a new object you take up memory and if you don't free it, your application will be a memory collector.

Hope it helps,

Adele

Former Member
0 Kudos

Hi,

The only scenario where I know that garbage collector should be used is when UDF, UDT, and Keys are created using metadata objects. In any other scenario, .Net and SBO are able to handle memory properly.

Regards,

Ibai Peñ