473,396 Members | 1,779 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Out of memory eventhough Garbage collection is in the code

Hi,
After calling this function 190 times, i get an exception
at the point of exception. The stack trace says:
StackTrace " at
System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) at
Procédo.MainApp.QualityCheckClass.EvaluateTiffImag e(ThreadM
essageClass& displayObject, String fileName, String
startingPageNum, String fileExt) in
D:\src\Procédo\MainForm\QualityCheck.vb:line 3957"
String

The code is:

Private Function EvaluateTiffImage(ByRef displayObject
As ThreadMessageClass, ByVal fileName As String, _

ByVal startingPageNum As String, ByVal fileExt As String)
As Boolean

Dim result As Boolean = False

' count of images in the tiff file
Dim imageIndex As Integer = 0

Dim propertyValues As Byte() = Nothing
Dim compressionString As String = ""
Dim compressionValue As Int16 = 0
Dim propertyItems As
System.Drawing.Imaging.PropertyItem()

displayObject.TargetWindow =
DISPLAY_ID.LIST_PROGRESS

Dim tiffData As TiffProcessingDataClass =
displayObject.MessageData

Try

' using the Imaging Managed objects. The Using
statement automatically handles clean up of the tiffImage
object
Using tiffImage As Image =
Image.FromFile(fileName, False)

If Not (tiffImage Is Nothing) Then

propertyItems = tiffImage.PropertyItems

For propertyIndex As Integer = 0 To
propertyItems.Length

' Compression property has an id of
259
If
propertyItems(propertyIndex).Id() = 259 Then

' The value of which is mapped
to a short type (i.e. Int16)
propertyValues =
propertyItems(propertyIndex).Value

' most significant bit is at
higher index
compressionString =
propertyValues(1) & propertyValues(0)
compressionValue =
Convert.ToInt16(compressionString)

tiffData.ImageCompression =
compressionValue

' tif images must have Group4
compression and jpg images must have huffman compression
If ((compressionValue =
IMAGE_COMPRESSION.COMPRESSION_CCITTFAX4) And (fileExt =
".tif")) Or _
((compressionValue =
IMAGE_COMPRESSION.COMPRESSION_HUFFMAN_CCITTRLE) And
(fileExt = ".jpg")) Then

result = True
displayObject.MessageText =
"...Found " & GetCompressionName(compressionValue) & "
Compression for: <" & fileName & ">."

Else
displayObject.MessageText =
"...Error: " & GetCompressionName(compressionValue) & "
Compression: <" & fileName & ">."
displayObject.IsError =
True
End If
DisplayMessage(displayObject)

' found what we are looking for
Exit For
End If
Next

Application.DoEvents()

' release the reference to the image
object
imageIndex += 1

Else

displayObject.MessageText = "...Error:
GDI+ error was unable to create a document for <" &
fileName & ">."
displayObject.IsError = True
DisplayMessage(displayObject)

End If
End Using
Catch ex As Exception

Dim innerExceptionString As String = Nothing

If ex.InnerException Is Nothing Then
innerExceptionString = "No inner exception"
Else
innerExceptionString =
ex.InnerException.InnerException.Message
End If

displayObject.MessageText = "An exception
occurred: <" & ex.Message & ">, this error happened when "
& _

"Procedo was trying to process file: <" & fileName & ">
inner exception: <" & _

innerExceptionString & ">."
displayObject.IsError = True
displayObject.TargetWindow =
DISPLAY_ID.LIST_RESULT
DisplayMessage(displayObject)

End Try

GC.Collect()
GC.WaitForPendingFinalizers()

Return result
End Function

Thanks for any help,
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 3 '08 #1
9 2291
Victory wrote:
Hi,
After calling this function 190 times, i get an exception
at the point of exception. The stack trace says:
StackTrace " at
System.Drawing.Image.FromFile(String filename, Boolean
useEmbeddedColorManagement) at
Procédo.MainApp.QualityCheckClass.EvaluateTiffImag e(ThreadM
essageClass& displayObject, String fileName, String
startingPageNum, String fileExt) in
D:\src\Procédo\MainForm\QualityCheck.vb:line 3957"
String
Don't call GC.Collect in your code. There is nothing in your code that
gets better from it. The garbage collector will perform a collection
when needed.

Have you tried to load only the specific file where the error occurs?
It's possible that the error comes from a corrupt file instead of an
actual lack of memory.

--
Göran Andersson
_____
http://www.guffa.com
Nov 3 '08 #2
Goran,
Yes, you are correct, that file causes the exception. How
can i know that the file is corrupt when the exception
returns "Out of memory"? Any ideas?
thanks,
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 3 '08 #3
Create smaller Try blocks, to isolate the error to a specific procedure.

"Victory" <cs****@devdex.comwrote in message
news:ep**************@TK2MSFTNGP06.phx.gbl...
Goran,
Yes, you are correct, that file causes the exception. How
can i know that the file is corrupt when the exception
returns "Out of memory"? Any ideas?
thanks,
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 3 '08 #4
James,
In general the isolation method you described works. In
this case however, the Image.LoadFrom is the cause of the
exception.
Thank you anyways,
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 3 '08 #5
There's nothing special about this case. If the error occurs at that line
you know that the file must be corrupt.

"Victory" <cs****@devdex.comwrote in message
news:uj****************@TK2MSFTNGP04.phx.gbl...
James,
In general the isolation method you described works. In
this case however, the Image.LoadFrom is the cause of the
exception.
Thank you anyways,
Mars
Nov 3 '08 #6
Or the file is so large that there isn't enough memory to process it.

On Tue, 4 Nov 2008 09:59:35 +1100, "James Hahn" <jh***@yahoo.com>
wrote:
>There's nothing special about this case. If the error occurs at that line
you know that the file must be corrupt.

"Victory" <cs****@devdex.comwrote in message
news:uj****************@TK2MSFTNGP04.phx.gbl...
>James,
In general the isolation method you described works. In
this case however, the Image.LoadFrom is the cause of the
exception.
Thank you anyways,
Mars
Nov 4 '08 #7
Unlikely. How large is the file?

"Jack Jackson" <jj******@cinnovations.netwrote in message
news:eq********************************@4ax.com...
Or the file is so large that there isn't enough memory to process it.
Nov 4 '08 #8

The file is actually small only 141KB.
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 6 '08 #9
Yes. 'Out of memory' almost always means 'corrupted' for a TIF file. It's a
characteristic of the data structures used that the decoding algorithms are
generally unable to determine when they are using invalid data. and simply
continue to issue requests for more memory. Garbage collection won't help,
as the memory appears to be in use.

"Victory" <cs****@devdex.comwrote in message
news:ur**************@TK2MSFTNGP06.phx.gbl...
>
The file is actually small only 141KB.
Mars

*** Sent via Developersdex http://www.developersdex.com ***
Nov 7 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
3
by: Ian Taite | last post by:
Hello, I'm exploring why one of my C# .NET apps has "high" memory usage, and whether I can reduce the memory usage. I have an app that wakes up and processes text files into a database...
25
by: Zeng | last post by:
I finally narrowed down my code to this situation, quite a few (not all) of my CMyClass objects got hold up after each run of this function via the simple webpage that shows NumberEd editbox. My...
6
by: Andy | last post by:
Along with many others I've noticed the large amount of memory that can be taken up by the aspnet_wp.exe. I've found that I can better control and limit this memory consumption by including a...
8
by: Adrian | last post by:
Hi I have a JS program that runs localy (under IE6 only) on a PC but it has a memory leak (probably the known MS one!) What applications are there that I could use to look at the memory usage of...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
2
by: roger.dunham | last post by:
I am trying to identify whether a .NET 1.1 application that I have written has a memory leak. I thought I understood how .NET memory management worked, but it appears that there is more to it...
2
by: Jack Jackson | last post by:
On Wed, 11 Jun 2008 07:32:30 +0200, "Fred" <foleide@free.fr.invalid> wrote: If the control will soon be eligible for garbage collection, then no. If the control won't be eligible for garbage...
11
by: dhtml | last post by:
(originally mis-posted on m.p.s.jscript...) I've just closed all windows in Firefox and its using 244MB of memory. I have no idea why. I had GMail open, a page from unicode, the CLJ FAQ. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.