Link to home
Start Free TrialLog in
Avatar of danielsnook
danielsnook

asked on

error 7 out of memory

Hi!

I implemented an OCX containing 2 pictureboxes controls.
Then in a simple application (one form, one button), I load at starting this OCX:

Private Sub Form_Load()
dim i as long

for i = 1 to 20000
   load myOcx(i)
next i

end sub

The OCX loading does not finish well and I get 2 different errors according to the case:

debug:
the applicattion crashes with "error 7 out of memory"
and the number of OCXs loaded is 2374.

release:
the application crashes with "Unable to load OCX, OCX might be obsolete" => and this is not the case!

The memory of my computer is 512Mo and the application
use about 32Mo in debug and 15Mo in reslease.

1- Does anyone already had this problem?
2- Is there a limit of loaded controls on a form?
3- Is there a way to control the amount of memory allocated for the application?

Thanks!
Daniel

Avatar of DanAvni
DanAvni
Flag of Israel image

a few pointers:
1. VB can not load an infinite number of OCX controls into a control array.
2. each picture box creates it's own Device Context (DC) and t's own Windows Handle (hwnd) this takes up windows memory and that might be what you are running out of.
I would suggest creating instead of the picture box control the Image control which is lighter on system resources.

ASKER CERTIFIED SOLUTION
Avatar of DanAvni
DanAvni
Flag of Israel image

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
maybe if you tell us what you are trying to achieve with the 20,000 ocx, then someone might know another way of producing the same result.
have you tried monitoring memory usage during the load of the ocx??
Avatar of danielsnook
danielsnook

ASKER

My application is a thumbnail viewer allowing to show pictures (JPEG, 150x100 pixels) in a directory.
Therefore, I need to load my thumbnails OCX then load picture thanks to the device context (DrawDibToDC WinAPI) of the picturebox of the OCX.

What do you mean by monitoring memory usage?
I kept and eye on memory during loading, and of course it increase, but when the app craches the memory used is lower than the max available on my machine.
A better means would be to add a single image object and a single picture object and use the image object on your form (visible) and the picture object (hidden) to load each picture and size it accordingly, then paste the picture into the image and move onto the next one.  You can hotspot the thumbnail with mouse coords taken while it's hovering over the image.
danielsnook:
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 DanAvni's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer