• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 210
  • Last Modified:

error 7 out of memory


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:

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

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?


1 Solution
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.


for info on the maximal number of controls on a form
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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??
danielsnookAuthor Commented:
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.
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?
Moderator, my recommended disposition is:

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

DanRollins -- EE database cleanup volunteer

Featured Post

Independent Software Vendors: 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!

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