Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

OCR increases my memory...

Solved!
Go to solution

 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)

Dim readString As String = ""

 

CWIMAQVision.ReadImage(Image, CurDir() & "\Image.bmp")

NIOCR.ReadText(Image, readString)

 

Text1.text = readString

End function 

 

 

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...

 

 

 

Message Edited by *Shadow* on 08-05-2009 11:16 AM
Message Edited by *Shadow* on 08-05-2009 11:18 AM
0 Kudos
Message 1 of 5
(3,862 Views)

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)

Dim 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

End function 

 

 

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...

 

 

0 Kudos
Message 2 of 5
(3,841 Views)
Solution
Accepted by topic author *Shadow*

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.

Waleed El-Badry MSc.,MCPD, ISTQB Certified Tester
Assistant Lecturer
Mechatronics Department
Faculty of Engineering
Misr University for Science & Technology



View Waleed El-Badry's profile on LinkedIn

Message 3 of 5
(3,804 Views)

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!

 

 

0 Kudos
Message 4 of 5
(3,788 Views)

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.

Waleed El-Badry MSc.,MCPD, ISTQB Certified Tester
Assistant Lecturer
Mechatronics Department
Faculty of Engineering
Misr University for Science & Technology



View Waleed El-Badry's profile on LinkedIn

Message 5 of 5
(3,773 Views)