on 05-26-2011 6:13 PM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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";
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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)
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
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
User | Count |
---|---|
108 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.