PDA

View Full Version : Releasing memory



Unregistered
July 5, 2002, 00:29:58
I'm trying to track down a memory leak in my program. Do you have any suggestions as to improving this code? In particular, do I need to GlobalFree v or something? As you can see I call both .MemoryReleaseImageData v and Erase v

Public Sub GetImage(ctlIC As ICImagingControl, ctlPic As PictureBox)
Dim v() As Byte
Dim lBase As Long

lBase = (3& * PIX_WIDE * PIX_HIGH * iPtr) + (3& * PIX_WIDE * PIX_HIGH * NUM_FRAMES * iCam)
With ctlIC
.MemorySnapImage
'switches here as soon as image has been captured to allow maximum time to settle
'before returning to this routine for capturing next camera
Call SwitchCamera(ctlIC)
v = .MemoryGetImageData

If frmVidCapture.WindowState <> 1 Then
StretchDIBits ctlPic.hdc, 0, 0, PIX_WIDE, PIX_HIGH, 0, 0, PIX_WIDE, PIX_HIGH, _
VarPtr(v(0, 0)), VarPtr(g_bi24BitInfo.bmiBufPtr), 0, vbSrcCopy
End If

Put #1, lBase + 5, v

.MemoryReleaseImageData v
Erase v
End With
End Sub

Public Sub SwitchCamera(ctlIC As ICImagingControl)
Dim sTemp As String

With ctlIC
g_iCamera = (g_iCamera + 1) Mod NUM_CAMERAS
If g_iCamera = 1 Then
sTemp = "02 Video: Composite"
Else
sTemp = "01 Video: Tuner"
g_iBufPtr = (g_iBufPtr + 1) Mod NUM_FRAMES
End If

.InputChannel = sTemp

If .Brightness <> iBrightness(g_iCamera) Then
.Brightness = iBrightness(g_iCamera)
End If
If .Contrast <> iContrast(g_iCamera) Then
.Contrast = iContrast(g_iCamera)
End If
End With

End Sub


This message was originally posted by Paul Jackson in the old IC Imaging Control Support Forum.

Unregistered
July 5, 2002, 18:51:52
Hello,

There is one handle leak in the startLive method that will be fixed in the next update of IC Imaging Control. The way you are using MemorySnapImage causes an implicit call to LiveStart. I would suggest a different way of getting the image:

1) Setup the device and do the following initialisation at the beginning of the program:

ICImagingControl1.LiveDisplay = False
ICImagingControl1.LiveCaptureContinuous = False
ICImagingControl1.LiveStart

2) the function that switches the input and gets the image could look like this:

ICImagingControl1.MemorySnapImage
If i >= ICImagingControl1.InputChannels.Count Then
i = 1
Else
i = i + 1
End If

ICImagingControl1.InputChannel = ICImagingControl1.InputChannels.Item(i).Name
Picture1 = ICImagingControl1.Picture

where i is global variable containing the index of the currently selected input.


Best regards
Johannes
IC Support


This message was originally posted by IC Support in the old IC Imaging Control Support Forum.

Unregistered
July 5, 2002, 23:06:56
I made the simplest program I could to observe the memory usage.
This program will consume about 700 kilobytes per hour as shown by the Mem Usage in Task Manager (started at 7812 KB increased to 8532)
Could you please verify this on one of your computers? Is the problem in the OCX, DirectX, the Conexant Capture driver (tweaked BT848 drivers from Ivan Uskov) or what?
I don't want to have to start over again after purchasing all of this.

Thanks in advance.

Timer1.Interval is set to 200 msecs.
IC1.Device="Conexant Capture"
.InputChannel="01 Video: Tuner"
.MemoryCurrentGrabberColorFormat="RGB24"
.VideoFormat="YUY2 (320x240)"
.VideoNorm="PAL_B"


Option Explicit

Private Sub Form_Load()
With IC1
.LiveDisplay = False
.LiveCaptureContinuous = False
.LiveStart
End With
End Sub

Private Sub Timer1_Timer()
Dim v As Variant
With IC1
.MemorySnapImage
v = .MemoryGetImageData
.MemoryReleaseImageData v
End With
End Sub

Private Sub Form_Unload(Cancel As Integer)
With IC1
.LiveStop
End With
Set Form1 = Nothing
End Sub


This message was originally posted by Paul Jackson in the old IC Imaging Control Support Forum.

Unregistered
July 6, 2002, 02:26:50
Some further information:
It typically jumps by 4 kilobytes every 15 seconds. Is there some significance to these numbers?
It sometimes drops down a bit before climbing back up.


This message was originally posted by Paul Jackson in the old IC Imaging Control Support Forum.

Unregistered
July 8, 2002, 17:36:06
Hello,
Due to a problem in an API function, "MemoryReleaseImageData" does not free up all data that was allocated in "MemoryGetImageData". We will fix this problem in the next update.

Best regards
Johannes
IC Support


This message was originally posted by IC Support in the old IC Imaging Control Support Forum.

Unregistered
July 8, 2002, 22:54:39
When can I expect an update to fix this?


This message was originally posted by Paul Jackson in the old IC Imaging Control Support Forum.

Unregistered
July 9, 2002, 11:50:34
Hello,

We are discussing the schedule for a new service pack.

Best regards
Johannes
IC Support


This message was originally posted by IC Support in the old IC Imaging Control Support Forum.