Link to home
Start Free TrialLog in
Avatar of kruege19
kruege19

asked on

Excessive use of RAM with ClipBoard and ImageControl

I've got a problem that's driving me crazy. First, I was having problems getting MSChart to redraw without "blinking" in a very annoying manner. The solution I found to this was to copy the Chart to the clipboard and then display it with an image control:

frmMainScreen.StripChart.ChartData = arrStripChartData
Clipboard.Clear
frmMainScreen.StripChart.EditCopy
frmMainScreen.imgChart.Picture = Clipboard.GetData
Clipboard.Clear

This totally cured the "blinking" problem but has also created another side effect. This method of refreshing the image is used about 2 times per second. I've been monitoring the system resources, and the RAM useage is increasing linearly with time. I have verified that it is the line:

frmMainScreen.imgChart.Picture = Clipboard.GetData

that is causing the problem. I believe that every time I copy the image from the clipboard to the image control, that a copy is being stored somewhere in RAM and I can not figure out why, where, or how to remove it.

Please help!

And as another added annoyance, when I'm running the program from within VB6, the memory never gets freed even when I exit the debug mode (only when I completely exit the VB environment). At least when I run a compiled .exe, it cleans up after itself when I exit.
Avatar of JohnMcCann
JohnMcCann

I think the leak is due to not cleaning up the intiial picture during refresh.

Also if you set the Redraw property imgChart to true.  The number of redraws should be cut.

and one last though

If you lock the chart before update the flickering disapears.

If you wish for a clearer explanation just ask.
Also puting the chart on the clipboard is very bad programming.  What haappens if it is changed.

Avatar of kruege19

ASKER

I guess my newbie status will become evident here, but yes I do need more info:

How to I "clean up" the initial picture during refresh?

How would setting the Redraw property to True change the number of redraws? I'm explicity changing the image contents once every 500mS.

Locking the MSChart control before changing the data will stop the flickering? How do I "Lock" the control?

I should probably say more about what I'm doing. I'm creating a strip chart that scrolls across the screen displaying time values of certain parameters (like an EKG strip). So the data needs to move to the right with each time step and a new data point is added to the beginning of the series.

As for the clipboard issue, I totally agree that it is sloppy, but this software is only a demo of proposed features in our product, not software intended for use or distribution.
I guess my newbie status will become evident here, but yes I do need more info:

How to I "clean up" the initial picture during refresh?

How would setting the Redraw property to True change the number of redraws? I'm explicity changing the image contents once every 500mS.

Locking the MSChart control before changing the data will stop the flickering? How do I "Lock" the control?

I should probably say more about what I'm doing. I'm creating a strip chart that scrolls across the screen displaying time values of certain parameters (like an EKG strip). So the data needs to move to the right with each time step and a new data point is added to the beginning of the series.

As for the clipboard issue, I totally agree that it is sloppy, but this software is only a demo of proposed features in our product, not software intended for use or distribution.
I think the Lock on the window will work best try this first.

Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long

LockWindowUpdate MSCHART1.hWnd

'Set your data

LockWindowUpdate False

To set the picture to nothing

set frmMainScreen.imgChart.Picture = Nothing
set frmMainScreen.imgChart.Picture = Clipboard.GetData



Well, I tried both of the suggestions, and neither made a difference. Locking the window doesn't stop the Chart from "blinking" whenever it redraws (and its being redrawn every 500mS). I actually prefer to use the image technique anyway because it allows me to add labels (because they are actually being added to the image, and not the chart).

I also tried the Nothing command and it didn't do anything for the memory leak...
ASKER CERTIFIED SOLUTION
Avatar of JohnMcCann
JohnMcCann

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You may need to set property of imgChart namely

AutoRedraw to true.
Scalemode = vbPixels
kruege19:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
Avatar of DanRollins
Moderator, my recommended disposition is:

    Accept JohnMcCann's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer