Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

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.
0
kruege19
Asked:
kruege19
1 Solution
 
JohnMcCannCommented:
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.
0
 
JohnMcCannCommented:
Also puting the chart on the clipboard is very bad programming.  What haappens if it is changed.

0
 
kruege19Author Commented:
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.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
kruege19Author Commented:
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.
0
 
JohnMcCannCommented:
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

0
 
JohnMcCannCommented:
To set the picture to nothing

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



0
 
kruege19Author Commented:
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...
0
 
JohnMcCannCommented:
Ok this must work

Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long


Private Sub imgChart_Click()
Dim StripChartDC As Long

   StripChartDC = GetDC(StripChart.hwnd)
   BitBlt imgChart.hdc, 0, 0, imgChart.ScaleWidth, imgChart.ScaleHeight, StripChartDC, 0, 0, vbSrcCopy
   imgChart.Refresh
End Sub


I've put the logic in te click event but that just to demonstrate how it works.
0
 
JohnMcCannCommented:
You may need to set property of imgChart namely

AutoRedraw to true.
Scalemode = vbPixels
0
 
CleanupPingCommented:
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?
0
 
DanRollinsCommented:
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now