cancel
Showing results for 
Search instead for 
Did you mean: 

release RAM

CarlesCostaMun
Participant
0 Kudos

Hi everybody,

How can I release the RAM memory?

I need to import many rows (> 10000) and insert through UDO in two tables (Document and document lines)

I 've tried with:


GC.Collect()
GC.WaitForPendingFinalizers()

after


                    oGeneralService.Update(oGeneralData)
                or 
                    oGeneralService.Add(oGeneralData)

but don't work and the precess fail because the RAM has grown too much

What can I do?

Thanks

Carles

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

You may try this to release object.

Private sub ABC

Dim oJrnl As SAPbobsCOM.JournalEntries

Try

oJrnl = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)

Catch ex As Exception

SBO_Application.MessageBox(ex.Message)

Finally

System.Runtime.InteropServices.Marshal.ReleaseComObject(oJrnl)

End Try

End Sub

rasmuswulff_jensen
Active Contributor
0 Kudos

We use

GC.Collect()

and that works fine for use... Some people claim that

Marshal.ReleaseComObject

http://msdn.microsoft.com/en-us/library/System.Runtime.InteropServices.Marshal.ReleaseComObject.aspx

is a better way to do it.

It could be that you are on a patchlevel that have memory leaks (happens from time to time) so please check patch-notes for patches that are higher than the one you are running.

Also try to limit the amount of calls to sub-objects... Example

Documents oDoc;
oDoc.Lines.ItemCode = "XXX";
oDoc.Lines.ItemName = "XXX";

is worse than


Documents oDoc;
Document_Lines oDocLine = oDoc.Lines;
oDocLine.ItemCode = "XXX";
oDocLine.ItemName = "XXX";

CarlesCostaMun
Participant
0 Kudos

I've tried with

Marshal.ReleaseComObject

but throw an error

I'm looking for, I've found this:

SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)

Private Declare Function SetProcessWorkingSetSize Lib "kernel32.dll" (ByVal process As IntPtr, _
                                                                      ByVal minimumWorkingSetSize As Integer, _
                                                                      ByVal maximumWorkingSetSize As Integer) As Integer

(well, it doesn't free memory... it move it to swap so more RAM can be used by other process... not really a solution but can help)

I need only once, so I supose that is no incorrect... This is only to do an import. Is there any problem to use it?

Thanks

rasmuswulff_jensen
Active Contributor
0 Kudos

Hi Carles

We have used the

SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1)

for years in our main product (We call it every 10 second)... As you mention it does not really reduce the memory usage but just push it to the pagefile but if does not have any issues calling (If you did call it too often you would suffer a perfromance hit)

Former Member
0 Kudos

Hello

Read this thread, everything

Regdars

János

CarlesCostaMun
Participant
0 Kudos

Hi again,

I've tried your first solution, János, but does not work

I've tried:


            While Not oRcs.EoF
                Me.IPS()
                oRcs.MoveNext()
            End While

and, in IPS I add or update de record.

When I do 2000 records the memory is over 700MB

The second solution i don't understand. Can you be more explicit, please?

Thanks

Carles

Former Member
0 Kudos

Hello

in the Me.IPS() subrutine did you executed in this way?

Try
-....

...
Cacth

-....

Finally 
 GC.Collect()
 Set obj = Nothing
end try

Regards

János

CarlesCostaMun
Participant
0 Kudos

Hello János,

Yes, I do


        Finally
            GC.Collect()

            sCmp = Nothing
            oGeneralService = Nothing
            oGeneralParams = Nothing
            oRcsLin = Nothing
            oGeneralData = Nothing
            oSons = Nothing
            oSon = Nothing

        End Try

Here is where the memory grows:


            If iDocEntryExist > 0 Then
                oGeneralService.Update(oGeneralData)
            Else
                oGeneralService.Add(oGeneralData)
            End If

Thanks