08-05-2009 11:12 AM - edited 08-05-2009 11:18 AM
Hi...
I'm developing an application in VB.NET 2005, the problem is when I use the NIOCR ActiveX control in my application, the memory increases and is unable to manage it.
I saw another post with the same problem, but there is not an effective answer.
Here it is an "example" of my application:
Dim Image As New CWIMAQImage
Dim CWIMAQVision As New AxCWIMAQVision
Dim NIOCR As New AxNIOCR
Private Sub MainForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
CWIMAQVision.CreateControl()
NIOCR.CreateControl()
NIOCR.ReadOCRFile(CurDir() & "\Lot Number.abc", NIOCRReadOCRFileOptions.niocrReadAll)
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)
End functionDim readString As String = ""
CWIMAQVision.ReadImage(Image, CurDir() & "\Image.bmp")
NIOCR.ReadText(Image, readString)
Text1.text = readString
This is only an example, but is the principal idea...when I run the program I observe the memory leak...I think the NIOCR keeps the "Image" in memory avoiding the memory liberation...
Solved! Go to Solution.
08-06-2009 10:14 AM
Ok...I have been testing another solutions, I try to create the NIOCR control in the timer and disposed it, but the result is worst
Private Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs)End functionDim readString As String = ""
Dim NIOCR As New AxNIOCR
NIOCR.CreateControl()
NIOCR.ReadOCRFile(CurDir() & "\Lot Number.abc", NIOCRReadOCRFileOptions.niocrReadAll)
CWIMAQVision.ReadImage(Image, CurDir() & "\Image.bmp")
NIOCR.ReadText(Image, readString)
Text1.text = readString
NIOCR.Dispose()
NIOCR = Nothing
In each Timer iteration the memory starts to increase and in a few hours the program crashes...I dont know if I'm doing somthing wrong....
Now, my only answer is to divide my program in two: 1 the main application and 2 a program with the OCR process...when the main program requires an ocr process calls the 2nd program, it sends the OCR result and closes...
08-10-2009 10:29 PM
Have you tried to dispose the CWIMAQVision too?
Please just make sure after disposing objects, you use this line of code:
GC.Collect()
Tell me if it works or not and I shall resume figuring it out with you.
The other approach is to "place these controls on the form directly" as the meory leak might be caused due to ctrating objects on timer event (it is a bad practice).So at least create CWIMAQVision and NIOCR objects in Form_Load() event and don't dispose them.
08-11-2009 04:56 PM
Hi, thanks for your reply...
I reviewed my program... and I placed the controls on the form directly....
In the firts test the memory increases again, but I discovered the reason: My test reads an image each 50 miliseconds and there is not enough time to free the memory (I think) because when I paused it, the memory starts to free (In my last program i did not see this effect)
When I changed the conditions of the test, I used a 3 seconds (The real program reads an image each 2 minutes) and now the memory frees ok...
Thanks for your help!
08-12-2009 05:16 AM
Glad Shadow that First of all you tackled your problem and secondly that I gained a new .NET guy on this forum :manwink:
I believe your problem will be useful for many others to learn from.
Have a lovely day.