?
Solved

Excessive use of RAM with ClipBoard and ImageControl

Posted on 2003-02-23
11
Medium Priority
?
200 Views
Last Modified: 2013-11-25
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
Comment
Question by:kruege19
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8004414
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8004419
Also puting the chart on the clipboard is very bad programming.  What haappens if it is changed.

0
 

Author Comment

by:kruege19
ID: 8004449
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:kruege19
ID: 8004472
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8005195
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8005220
To set the picture to nothing

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



0
 

Author Comment

by:kruege19
ID: 8005417
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
 
LVL 5

Accepted Solution

by:
JohnMcCann earned 360 total points
ID: 8005539
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
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8005547
You may need to set property of imgChart namely

AutoRedraw to true.
Scalemode = vbPixels
0
 

Expert Comment

by:CleanupPing
ID: 8901243
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 8964185
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question