473,508 Members | 4,324 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Out of memory

59 New Member
im making a program that will create a new button for every file in a directory(my pictures) and the background image for the button will be the picture...but when i run it i get an out of memory error...here is the code
Dim dir As New DirectoryInfo(My.Computer.FileSystem.SpecialDirect ories.MyPictures)
Dim f As FileInfo
For Each f In dir.GetFiles

Dim newbutton As New Button
'below is where the problem is'
newbutton.BackgroundImage = Image.FromFile(f.FullName)
newbutton.Text = f.Name

Me.Controls.Add(newbutton)

Next f
Mar 24 '08 #1
6 885
kadghar
1,295 Recognized Expert Top Contributor
im making a program that will create a new button for every file in a directory(my pictures) and the background image for the button will be the picture...but when i run it i get an out of memory error...here is the code
Dim dir As New DirectoryInfo(My.Computer.FileSystem.SpecialDirect ories.MyPictures)
Dim f As FileInfo
For Each f In dir.GetFiles

Dim newbutton As New Button
'below is where the problem is'
newbutton.BackgroundImage = Image.FromFile(f.FullName)
newbutton.Text = f.Name

Me.Controls.Add(newbutton)

Next f
try writing the files name in the command button, instead of adding it as the bgimage.

newbutton.caption = f.FullName

instead of

newbutton.BackgroundImage = Image.FromFile(f.FullName)

that way you'll see how many buttons you're generating and how they look without a background image.

If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

HTH
Mar 24 '08 #2
Killer42
8,435 Recognized Expert Expert
Yes, without seeing the code it's difficult to give a definite answer. But images can be quite memory-hungry and loading a lot of them at once might use it all up.

Are these buttons all visible at once, or do you have to scroll, or what? If you really do need to show the images on them, there are a number of things you might try. For example, reducing each image to a thumbnail for display, rather than simply "showing it small". Or perhaps you could get away with only loading them as they scroll onto the display, and throwing them away when they scroll off.
Mar 25 '08 #3
raids51
59 New Member
try writing the files name in the command button, instead of adding it as the bgimage.

newbutton.caption = f.FullName

instead of

newbutton.BackgroundImage = Image.FromFile(f.FullName)

that way you'll see how many buttons you're generating and how they look without a background image.

If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

HTH
yah. that works i was doing that before... mabey my laptop just cant handle it
Mar 25 '08 #4
raids51
59 New Member
try writing the files name in the command button, instead of adding it as the bgimage.

newbutton.caption = f.FullName

instead of

newbutton.BackgroundImage = Image.FromFile(f.FullName)

that way you'll see how many buttons you're generating and how they look without a background image.

If this works fine, then the problem is that you're using many and heavy images and your computer cannot handle them

I this doesnt work, may be the problem is with the loop, or with the sub-files you might have.

HTH
but the pictures are only 2kb
Mar 25 '08 #5
raids51
59 New Member
well... i found out what is wrong:D...the problem wasnt because of the file size...it was because the program was listing EVERY file in the my pictures file...including the systems files(thumbs.db and the desktop.ini or w.e)which werent pictures...so apparently you cant load a picture from a file when the file isnt a picture file:P
Mar 29 '08 #6
Killer42
8,435 Recognized Expert Expert
so apparently you cant load a picture from a file when the file isnt a picture file:P
Well, that's a bit disappointing, then. :)

Glad to see you got the problem sorted, though.

By the way, I wouldn't set too much store by the file size. A 2KB JPEG file, for instance, can decompress to quite a large image. This will take up lots of RAM if held there as a bitmap (which I think they are).
Mar 31 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
2027
by: Andreas Suurkuusk | last post by:
Hi, I just noticed your post in the "C# memory problem: no end for our problem?" thread. In the post you implied that I do not how the garbage collector works and that I mislead people. Since...
4
12996
by: Frank Esser | last post by:
I am using SQL 8 Personal edition with sp2 applied. I set the max server memory to 32MB and leave the min server memory at 0. When my application starts hitting the database hard the memory usage...
4
2563
by: Franklin Lee | last post by:
Hi All, I use new to allocate some memory,even I doesn't use delete to release them. When my Application exit, OS will release them. Am I right? If I'm right, how about Thread especally on...
9
2327
by: Mike P | last post by:
I know everything about reference counting and making sure you don't have large objects lying around. I have also profiled my app with multiple tools. I know about the fact GC collects memory but...
22
3449
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
14
20747
by: Alessandro Monopoli | last post by:
Hi all, I'm searching a PORTABLE way to get the available and total physical memory. Something like "getTotalMemory" and it returns the memory installed on my PC in bytes, and...
1
3003
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
5
24599
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
2021
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
5
505
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
7228
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7393
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7502
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5635
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5057
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3206
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3191
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
426
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.