locked
Visual Basic.NET 2005 - OutOfMemoryException

    Question

  • I have a high speed equipment test application running in VB2005 and Framework 2.0.  I have this application running in a PC with 2GB RAM.

     

    I get System.OutOfMemoryException very often on this application. As everyone must be aware the application stops and has to be restarted. I have seen in web searches about a Microsoft HOTFIX for this issue, and some other reports that there is really no fix for this issue.

     

    Looking for some help in this issue. I am in a manufacturing world where this application is critical for product testing.

     

    Appreciate any feedback on this.

     

     

    Sunday, August 19, 2007 1:22 AM

Answers

  • HKNet,

     

    HKNet,

     

    Thanks for your reply with the description and the code snippet. The OutOfMemory exception seems to happen on the gBackground.Read() method. However, I cannot find the related information on this method. If it is convenient, please check and provide the code of this method in your application.

     

    Basically, a 32 bit process has 2GB (at most 3GB if OS supports) user mode virtual address space to use. The 2GB size is not affected by how much physical memory or paging file you have. When the address space is used up (e.g. when the application tries to allocate the memory but cannot find a continuous block of address space large enough to satisfy the allocation request), OutOfMemoryException will be thrown. Generally speaking, when the private bytes usage of a process reaches above 1GB, OOM will occur.

     

    OOM exceptions are usually caused by memory leak. For example,  the developer allocates memory but forgets to free it after using it. For .Net applications, if we create a large number of objects and keep references to them (like adding event handlers to a WinForm control repeatedly but never removing them), garbage collection will not be able to reclaim them. Hence memory leak occurs.

     

    Occasionally, OOM exception can also be a results of COM call. If the called method return a HRESULT 8007000e (E_OUTOFMEMORY), it can also be translated to OOM exception in .Net.

     

    In order to diagnostic OutOfMemory exception, it is necessary to have a sample to reproduce your problem on the forum support. If it is not possible, please post the question in PSS (Microsoft Product Support Services) for the further memory dump analysis. I hope the words above on this kind of problems can provide you some idea.

     

    Thanks again for your question.

     

    Thursday, August 23, 2007 8:44 AM

All replies

  • Does this happen when running your app from the IDE and debugging it? If so... where abouts is the code breaking? Is it the same place every time? Any chance it's happening on a property?

    Sunday, August 19, 2007 1:23 AM
    Moderator
  • This happens when it is running as an EXE. I notice that at the time this crashes, my page file usage is around 1.3GB. I have a 2 GB RAM, so i didnt think that was an issue.

     

    After reading thru so many blogs, sounds like a lot of people are having this issue using Framwork 2.0 .

     

    Monday, August 20, 2007 3:17 PM
  • This is not a WPF problem. Moving from WPF Forums.

     

    Tuesday, August 21, 2007 4:24 AM
  • HKNet,

     

    Since the high speed equipment test application is running on .NET Framework 2.0 and VB 2005 IDE, could you please provide the related information on the "High speed equipment test application"?

     

    Is this a third-party or add-in application developed by yourself? Could you please provide the code snippet that cause the System.OutOfMemoryException?

     

    Thanks again for your question and waiting the the reply.

     

    Wednesday, August 22, 2007 9:34 AM
  • This application involves scanning analog data acquisition card at high sampling rate and performing some analysis on the signals.

    This application is developed by me. This application faults out when i am trying to read the analog signals, it always seems happen at the same point, the reason i know this is, even tho i am running EXE, i have error logging thruout the application lifecycle and when i review the error log, it tells me where it crashed and for what reason.

     

    Attached is the code snippet:

     

    Public Sub GetBackground()

    Try

    If Not gDaqRequest Then

    gDaqAvailable = False

    If gBackgroundActive Then

    'gBackgroundData is DAQ object

    gBackgroundData = gBackground.Read() 'Reading dataacquisition card

    If Not IsNothing(gBackgroundData) Then

    gSupplyRaw = gBackgroundData.Averages(gIdxSupply)

    '

    End If

    End If

    Else

    gDaqAvailable = True

    End If

    '

    Catch ex As Exception

    gErrorNew(6005, _

    "GetBackground", _

    Nothing, _

    "GetBackground Failed - " & ex.Message)

    End Try

     

     

    Wednesday, August 22, 2007 4:43 PM
  • HKNet,

     

    HKNet,

     

    Thanks for your reply with the description and the code snippet. The OutOfMemory exception seems to happen on the gBackground.Read() method. However, I cannot find the related information on this method. If it is convenient, please check and provide the code of this method in your application.

     

    Basically, a 32 bit process has 2GB (at most 3GB if OS supports) user mode virtual address space to use. The 2GB size is not affected by how much physical memory or paging file you have. When the address space is used up (e.g. when the application tries to allocate the memory but cannot find a continuous block of address space large enough to satisfy the allocation request), OutOfMemoryException will be thrown. Generally speaking, when the private bytes usage of a process reaches above 1GB, OOM will occur.

     

    OOM exceptions are usually caused by memory leak. For example,  the developer allocates memory but forgets to free it after using it. For .Net applications, if we create a large number of objects and keep references to them (like adding event handlers to a WinForm control repeatedly but never removing them), garbage collection will not be able to reclaim them. Hence memory leak occurs.

     

    Occasionally, OOM exception can also be a results of COM call. If the called method return a HRESULT 8007000e (E_OUTOFMEMORY), it can also be translated to OOM exception in .Net.

     

    In order to diagnostic OutOfMemory exception, it is necessary to have a sample to reproduce your problem on the forum support. If it is not possible, please post the question in PSS (Microsoft Product Support Services) for the further memory dump analysis. I hope the words above on this kind of problems can provide you some idea.

     

    Thanks again for your question.

     

    Thursday, August 23, 2007 8:44 AM
  • Bruno,

     

    Thanks for your insight into this. I will check in my code and look for the issue you have mentioned.

     

    Why doesnt the Garbage Collection work to free up memory? Isnt that the purpose of GC?

     

     

     

    Monday, August 27, 2007 2:00 PM