Results 1 to 26 of 26

Thread: "Out of Memeory" error

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    "Out of Memeory" error

    I'm working with the GDI+ and when I go to load an image it gives me the error

    I have tried declaring tImage different types (i.e. Bitmap) and still nothing. What's really interesting about this is that if I step through the program line by line, it works just fine. What gives?

    Here's my code:

    VB Code:
    1. Imports System.IO
    2. Imports System.Windows.Forms
    3. Imports System.Drawing
    4. Imports System.Drawing.Imaging
    5.  
    6. ...
    7.  
    8. Private tImage As Image
    9.  
    10. Private Sub LoadImage(ByVal ImagePath as String)
    11.  
    12.             tImage = Image.FromFile(ImagePath)
    13.  
    14. End Sub

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    Alright, well so far it has to do with the size of the picture? It crashes when loading 1.5MB pictures, but 29KB pics work just fine (I don't have to step through the program for it to load the picture).

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    bump. anyone?!

  4. #4
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    No idea. Could u zip some code and the image and post it here ?

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  5. #5
    Fanatic Member Graff's Avatar
    Join Date
    Jan 2002
    Location
    Calgary
    Posts
    668

    Re: "Out of Memeory" error

    A little more code might be helpful, especially the function/sub that calls the load image
    If wishes were fishes we'd all cast nets.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    I've bolded where I get the error.

    VB Code:
    1. Imports System.Drawing
    2. Imports System.Drawing.Imaging
    3.  
    4. Module mdlEditImage
    5.     Public Class clsWorkingImage
    6.  
    7.         Public imgWorking As Image 'The original image instance
    8.         Private strWorkingPath As String 'The path of the original image before processing a.k.a "The Drop Folder"
    9.         Public strOrgImagePath As String 'The path to where the Original image will be placed after processing
    10.         Public strProcImagePath As String 'The path to where the Processed image will be placed after processing
    11.  
    12.         Public Sub New(ByVal strImagePath As String)
    13.             Try
    14.                 strWorkingPath = strImagePath
    15.                 [B]imgWorking = Image.FromFile(strWorkingPath)[/B]
    16.                 strOrgImagePath = Dir(strWorkingPath) & "\Original\"
    17.                 strProcImagePath = Dir(strWorkingPath) & "\Processed\"
    18.             Catch er As Exception
    19.                 Throw er
    20.             End Try
    21.         End Sub
    22.     End Class
    23. End Module
    24. ------------------------------------------------------------------
    25. Imports System.IO
    26. Imports System.Windows.Forms
    27. Imports System.Drawing
    28. Imports System.Drawing.Imaging
    29.  
    30. Public Class frmMain
    31.     Inherits System.Windows.Forms.Form
    32.  
    33. WINDOWS FORM DESIGNER GENERATED CODE
    34.  
    35.     Private WithEvents fsw As New FileSystemWatcher
    36.     Private tImage As Image
    37.  
    38.     Private Sub HandleChangedCreatedDeleted(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Changed, fsw.Created, fsw.Deleted
    39.  
    40.         If System.IO.Path.GetExtension(e.FullPath) = ".jpg" Then
    41.  
    42.             If e.ChangeType = WatcherChangeTypes.Created Then
    43.  
    44.                 'Initialize picture || tWI = tmp Working Image
    45.                 Dim tWI As New clsWorkingImage(e.FullPath)
    46.             End If
    47.  
    48.         End If
    49.     End Sub
    50. End Class

  7. #7
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Nothing wrong with that code...could you upload the image somewhere ?

    Hopefully, this isn't the GDI+ overflow bug...you're patched aren't you ?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    you're patched aren't you ?
    I have
    VB.Net Version 7.1.3088 (2003)
    .Net Framework 1.1 Version 1.1.4322 SP1

    That's all I know. Besides, isn't the overflow virus related?

    Unfortunately, I cannot show you the picture, but it's a jpg w/ a resolution of 1997x4260 @ 240 dpi.

    just a reminder.. it does work with much smaller pictures.
    Last edited by jsun9; Feb 3rd, 2005 at 06:20 PM.

  9. #9
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    By "patched" I was refering to Windows patches. Anyway, if you can't post the picture somewhere for someone to see it might be difficult to get a grasp of the problem.

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    The actual picture that's being used? It's not just one picture, it's all of them. Here is an example: 999B.jpg

  11. #11
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Your clsWorkingImage class works fine for me.

    Just spotted something else though...could u ammend clsWorkingImage as follows:

    VB Code:
    1. Public Class clsWorkingImage
    2.  
    3.         Shared NumCount As Integer = 0
    4.         Public imgWorking As Image 'The original image instance
    5.         Private strWorkingPath As String 'The path of the original image before processing a.k.a "The Drop Folder"
    6.         Public strOrgImagePath As String 'The path to where the Original image will be placed after processing
    7.         Public strProcImagePath As String 'The path to where the Processed image will be placed after processing
    8.  
    9.         Public Sub New(ByVal strImagePath As String)
    10.             Try
    11.                 NumCount += 1
    12.                 Debug.WriteLine("Called " + NumCount.ToString + " times")
    13.                 strWorkingPath = strImagePath
    14.                 imgWorking = Image.FromFile(strWorkingPath)
    15.                 strOrgImagePath = Dir(strWorkingPath) & "\Original\"
    16.                 strProcImagePath = Dir(strWorkingPath) & "\Processed\"
    17.             Catch er As Exception
    18.                 Throw er
    19.             End Try
    20.         End Sub
    21.     End Class

    and see how many times the class objects load an image ? I have a feeling that the file system watcher may throw several events for each file, so loading several times a large image may give you an out of memory exception. If that is the case, this would also happen with smaller images but it would take more time for the error to occur.

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  12. #12
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    I sure am curious to know what happened, did that help or not jsun9 ?

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    ntg, that was a great theory. But, I checked it out and it only calls the sub once. I know fsw will in some cases call it multiple times. however, the HandleChangedCreatedDeleted Sub that I use to set my program in motion is only called once upon the creation of a file.

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    but get this, if i drop a second file.. it crashes.

  15. #15
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Well, you got me jsun9. If it's called only once I'm fresh out of any ideas - it's still runing fine on my box.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  16. #16
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Ehm...ok, it may be running fine on my box because I have lots of RAM. Do you do a imgWorking.Dispose() and imgWorking=Nothing at some point ?
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    I only set the class instance to nothing. I don't set imgWorking to nothing because there's no real place to do it. Do you think GDI+ doesn't support this file? The MSDN states it'll throw a memory error if the picture is unsported. But it's a jpg? Also, I have 1.5GB of RAM so I doubt it's really running out of memory.

  18. #18

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    If I set it up manually (take it out of the filesystemwatch event) it doesn't error. no idea why.

  19. #19
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Now I'm pizzed off
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  20. #20
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    First of all, you really need to do a .Dispose() since GC doesn't really do a good job with Images plus the image file itself stays locked for some time if you don't .Dispose().

    Now...I too got the error when I pasted several large images at once. I made a small change:
    VB Code:
    1. Threading.Thread.CurrentThread.Sleep(100)
    2. Dim tWI As New clsWorkingImage(e.FullPath)
    and I never got the error after that. Also, if you add:
    VB Code:
    1. Debug.WriteLine(e.ChangeType.ToString + "> " + e.Name)
    at the beginning of the file system watcher event code, you'll see that when you copy a new file there is a single created event and some changed events. Most of the time, these happen at the same millisecond, but every now and then they do occur some milliseconds apart. Best guess ('cause that's what it is, really) is that when the created event is fired the file is not yet completely copied and when you try to read it through Image.FromFile, GDI is missing some data and in some way it throws an out of memory exception I understand that this is completely unscientific and unsupported by any fact, it ain't even informed guessing but I can't think of anything else right now. If someone has some explanation, I'd love to hear it. I'll play with it some more and post anything that comes to mind.

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    yup. i think that explains it all. that's why it works with small files: by the time the fsw triggers the event and the image class is made, the file is already copied in its entirety.

    the sleep event works for now.. but what happens when you have a really huge file that takes 3 seconds to transfer? you could have a timer watch the file until it was completed, but that's just messy. but then again.. I bet if I drop multiple files at a time, it will only catch the first one if that.. a time may be my only option?!

    the created event is pretty weak.. there should be a finished_creating or final_change event to let the program know it's not going to be touched anymore.

  22. #22
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Yeah, something like finished_creating would help. I think that you'd need to use some kind of queue where newly created items would be inserted, then a background thread would check the queue and would then open a stream reader that checks the file size reported by the dir properties against the file size reported by stream reader - only when they're equal should you continue with opening the image. Or maybe a file open with exclusive read/write lock - that would fail unless file copy is done so again you can flag the file as being ok to open.

    This is pretty messy indeed, I wonder if there really isn't a better alternative...

    Edit: I'm missing the obvious again, when System.IO.File.GetLastWriteTime() stops changing the file must be complete.

    Cheers,
    NTG
    Last edited by ntg; Feb 7th, 2005 at 06:44 PM.
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  23. #23

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    yeah.. the queue is probably the safest. i'll give it a try and post the results. I appreciate your help ntg.. it was pleasant working with someone sincerely interested in finding out the results.

  24. #24
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: "Out of Memeory" error

    So about that finished_creating feature we were wishing we had...well, it's called WatcherChangeTypes.Created It works perfectly like a queue.

    I call it like this (the 3000 tells it to wait 3000 ms after last change before moving on.
    VB Code:
    1. fsw.WaitForChanged(WatcherChangeTypes.Changed, 3000)

  26. #26
    Frenzied Member ntg's Avatar
    Join Date
    Sep 2004
    Posts
    1,449

    Re: "Out of Memeory" error

    Geez, I didn't know that. Thanks for posting

    Cheers,
    NTG
    "Feel the force...read the source..."
    Utilities: POPFileDebugViewProcess ExplorerWiresharkKeePassUltraVNCPic2Ascii
    .Net tools & open source: DotNetNukelog4NetCLRProfiler
    My open source projects: Thales SimulatorEFT CalculatorSystem Info ReporterVSS2SVNIBAN Functions
    Customer quote: "If the server has a RAID array, why should we bother with backups?"
    Programmer quote: "I never comment my code. Something that is hard to write should be impossible to comprehend."
    Ignorant quote: "I have no respect for universities, as they teach not practicle stuff, and charge money for"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width