Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Usercontrol & picturebox missing memory


Reply
 
Thread Tools Display Modes
  #1  
Old 12-20-2002, 01:52 AM
beetlefeet
Guest
 
Posts: n/a
Question Usercontrol & picturebox missing memory


I'm having some trouble with a usercontrol i made (for a graphical button).
It uses 6 hidden pictureboxes.
3 pictureboxes for the source of graphical states (normal, rollover, clicked) ( controlarray picSrc(0,1,2) )
3 more for temporary pictures. ( picBut(0,1,2) )

at initialize time and usercontrol_resize i resize pictureboxes picBut() to the size of the usercontrol.
Then i fill them using picturebox.paintpicture from picSrc. (I use 3 paintpicture calls for each so i can scale the ends separatly from the middle so the buttons keep nicely pill shaped.)

Heres the code:
The actual variables and maths isn't important, that much works.


' left end
picBut(i).PaintPicture picSrc(i).Picture, 0, 0, butCurve2, ctlHeight, 0, 0, butCurve, butHeight
' middle
picBut(i).PaintPicture picSrc(i).Picture, butCurve2 - 10, 0, ctlWidth - (butCurve2 * 2) + 20, ctlHeight, butCurve, 0, butWidth - (butCurve * 2), butHeight
' right end
picBut(i).PaintPicture picSrc(i).Picture, ctlWidth - butCurve2, 0, butCurve2, ctlHeight, butWidth - butCurve, 0, butCurve, butHeight

at this point I also set the usercontrols maskimage property to one of the picBut()s, to get the transparency right.

"Set UserControl.MaskPicture = picBut(0).Image"

Now whenever i want to actually draw the button i just set the usercontrols image to the relevent picBut() depending on the mouse state etc. (another thing i tried that works the same is using usercontrol.paintpicture)
ie:
"Set UserControl.Picture = picBut(intState).Image" or
"UserControl.PaintPicture picBut(intState).Image, 0, 0"


Sorry if this is confusingly written so far, i'm getting to the point

Now this all works and looks fine.

But...
Looking at the task manager I see that each instance of the usercontrol uses multiple megabytes of memory. (the pictures are only ~ 150x50 pixels and there are only 3 states. The amount of memory used goes up fast with the size of the control. if i resize the control to around 400x200 or so it uses around 60+ megabytes of memory! this is for each instance or a form.

I've tried a few things.
By commenting out the lines about the memory problem goes
away. (but the control doesn't display anything :P )
Commenting them out one by one shows that they all play a part in the missing memory.

I'm not sure what the problem is. I thought the code looked safe and simple. I'm not doing anything tricky with the API or DC's or anything. I just can't figure where those megs of memory are going.

Also, the memory usage for the VBIDE in task manager doesn't go up, only the total system memory used does, and the memory coems straight back after deleting the usercontrol from the form, so it's not like the is memory being lost forever.

If anyone knows what could be causing this it would be a big help.
Reply With Quote
  #2  
Old 12-20-2002, 04:33 AM
Chris J Locke Chris J Locke is offline
Contributor
 
Join Date: Mar 2002
Location: Essex, UK
Posts: 690
Default

60MB of memory?! You don't mean KB?
Any chance of posting the control? (in a .ZIP or something)
Reply With Quote
  #3  
Old 12-21-2002, 03:48 AM
beetlefeet
Guest
 
Posts: n/a
Default

Quote:
60MB of memory?! You don't mean KB?
Unfortunately I do mean 60MB. It's completely strange, i cannot beging to imagine what on earth could be using it all.

I'm at home over the weekend, the code's at work, I'll get back to you regarding posting the control on monday.

thanks
Reply With Quote
  #4  
Old 12-22-2002, 06:29 PM
beetlefeet
Guest
 
Posts: n/a
Default

Heres the VB6 project for the control. (well it's actually just an EXE project which the usercontrol is part of.)

Edit: The file is attached in a post below.


Steps to show the problem:

- Open the project in VB6.
- Show the Form (Form1).
- Open taskmanager and go to the performance tab where it shows used memory.
- Click back to the form.
- Check memory used.
- Draw an AquaButton onto form1.
- Check memory.
- Resize AquaButton.
- Check memory.

My pc is win2k SP2 by the way, i haven't tested it elsewhere.

thanks to anyone who looks at it.

Last edited by beetlefeet; 12-22-2002 at 07:50 PM.
Reply With Quote
  #5  
Old 12-22-2002, 06:31 PM
beetlefeet
Guest
 
Posts: n/a
Default The Project Zipped

Heres the Zip.
Attached Files
File Type: zip aquabuttontest.zip (16.6 KB, 9 views)

Last edited by Banjo; 12-23-2002 at 04:42 AM.
Reply With Quote
  #6  
Old 12-22-2002, 07:37 PM
beetlefeet
Guest
 
Posts: n/a
Default

Oh the missing OCX is the desaware spyworks hook control. I forgot about that. Its used for capturing the mouse movements so i can do rollever effects.

I'll make a version that doesn't use the hook.

Also I'm going to use that report thread to moderator link to get them to delete this thread and then post the project back at the original thread.

thanks.
Reply With Quote
  #7  
Old 12-22-2002, 07:43 PM
ericgamer47's Avatar
ericgamer47 ericgamer47 is offline
Banned
 
Join Date: Nov 2002
Location: in a place i call *cough
Posts: 80
Default

what do you mean performance tab? i searched for task manager and found a program called taskman. so i opened that. and from there on i'm lost.. i dont see anything that says performance..
Reply With Quote
  #8  
Old 12-22-2002, 07:49 PM
beetlefeet
Guest
 
Posts: n/a
Default

Heres the file w/o the reference to the Desaware Hook control.

(sorry about that)

NB i'm not interested in the actual behavior of the button (mouseovers etc) I can get that working fine, just the memory usage.

Quote:
i dont see anything that says performance..
Hmm In my task manager (right click task bar and choose taskmanager) it has a performance tab which shows the amount of memory and cpu etc used. Might be different for different windows versions, i can't remember. I'm using win2k.
Attached Files
File Type: zip aquabuttontest.zip (16.4 KB, 6 views)
Reply With Quote
  #9  
Old 12-22-2002, 07:53 PM
ericgamer47's Avatar
ericgamer47 ericgamer47 is offline
Banned
 
Join Date: Nov 2002
Location: in a place i call *cough
Posts: 80
Default

well thats probably it.. and in that case, i wont be able to help very much... but 60MB! wow! that's a lot...
Reply With Quote
  #10  
Old 12-22-2002, 09:35 PM
beetlefeet
Guest
 
Posts: n/a
Default

I think i've got it sorted out. It 's an odd one and perhaps I should file a bug report about it or something. (i'm pretty sure it's not an error on my part).

here we go:

I had the UserControl's ScaleMode set to pixels.
and was using these lines to convert it to twips:

ctlWidth = UserControl.ScaleX(UserControl.ScaleWidth, vbPixels, vbTwips)
ctlHeight = UserControl.ScaleY(UserControl.ScaleHeight, vbPixels, vbTwips)

If i set the usercontrols scale mode back to twips and leave out the above calculation lines it does not use up that much memory, only a few kilobytes.

I'm guessing somewhere along the line in one of the paintpicture calls or somewhere, it is allocating memory for a DC or something on the usercontrol and accidently using the value for twips (or perhaps himetrics?) but allocating that number of pixels, thus allocating 15^2 times too much memory.

sound plausable?

How bizzare...

Thanks evr1 that took an interest, eric, chris.
Reply With Quote
  #11  
Old 12-22-2002, 10:06 PM
shmoove shmoove is offline
Senior Contributor

Retired Leader
* Expert *
 
Join Date: Sep 2002
Location: Israel
Posts: 918
Default

Quote:
Originally posted by OnErr0r in a different post
Height and Width are the overall size of the form and are always in twips, regardless of the ScaleMode.
If you're using Width and Height of the control to set the values then that's probably your answer.
__________________
Have you tried looking right in front of you (or at least in MSDN)?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->