|
-
Mar 18th, 2000, 09:16 PM
#1
Thread Starter
Registered User
...Hey all
!!! PLEASE HELP MY DUMB <snip> BRAIN
,)Every 10 times that I'm running and exiting my program(not the EXE
"!I get the most <snip> sentence exists on earth: "Out Of Memory
:I load to the form this things
.42 picture-boxes
.120 lines controls
.7 WAV files
"I exit the program just with the command: "End
.I need to correctly unload all of these controls in order to free-up my RAM
???What the hell should I do
! I CANT SOLVE IT FOR MONTHS
.P.S: I develop the program under Celeron 500MHZ and 64 MB SDRAM
P.S2: I tried the "unload", ".close", "blah=empty" commands, but it did NOT
.)work,(Or I didnt use it correctly
,Desperate & waiting for your Answer
.Lior, An Israeli Programmer
rogrammer.
(Edited for strong language - James)
[Edited by James on 03-19-2000 at 11:32 AM]
-
Mar 18th, 2000, 09:25 PM
#2
Member
I have the same problem with my massive college project. the reason you get that message is because the ram maybe allocated somewhere else, so quit all othe app's, if that does not work, go to www.download.com (cnet) and search for Rambooster, this program is great for freeing up unused memory.
-
Mar 18th, 2000, 11:19 PM
#3
Lively Member
this is just my understanding, so i could be wrong.
ending a program with the end command halts the program without allowing the program to release the memory that it is using: variables, object, etc. Using "unload me" statement should allow the release all memory being used by that form.
-
Mar 19th, 2000, 03:23 AM
#4
New Member
Yes, you should explicitly unload all those controls with the unload statement. Especially picture boxes, a very heavy control memory wise. You can step through the Forms and Controls collections and “Unload Me” on each one.
And 120 line controls? Even a lightweight control like that, 120 is a lot!
May I suggest you consider other design approaches that would make better use of the system resources? Don’t forget the user may want to have other programs running at the same time.
Instead of line controls, why don’t you use the line method? It works on forms and picture boxes directly, and takes no memory at all, really.
And instead of all those picture boxes, could you use image controls instead? Image controls are much kinder on system resources than picture boxes. If you are drawing in those picture boxes with lines and circles and text etc, you can still draw them in image controls (just use one picture box, draw the lines and circles and text and whatever on the picture box, then transfer the image to the image control using the picture box’s image property). This way you only need one picture box, and multiple image controls.
Another approach, if you need to display multiple images, you can “paint” a picture on a form or picture box (or an image control using the method above) with the paintpicture method. You have a lot of control on position and sizing, etc with this method. This way you can have hundreds of pictures on only a single picture box or form.
Also, I hope you are using control arrays for these multiple controls. VB has a limit on how many uniquely named controls you can have, and an array of controls consumes less space (and is easier to handle) than the other way.
I hope this helps a little.
Rob
-
Mar 19th, 2000, 03:50 AM
#5
Thread Starter
Registered User
Still doesnt work!
I have a few things to say:
1) I've downloaded Rambooster - even after optimizing 63 MB I get the same "out of memory" message.
2) I know what I need, and I really need Picture-boxes and not Images, And I DO need 120 LINE CONTROLS - because of the background of an image that is being dragged.
never mind, It's kinda complicated, but I want you to know that all what i told you that I need, I REALLY NEED.
119 Line controls wo'nt help me, I need all of the 120 of them.
About the "Unload" procedure, It tells me I cant unload the control in design mode or something like that.
If anybody just think of something that might would help me, PLEASE leave a reply.
Thanks,
Lior, A desperated Israeli programmer.
-
Mar 19th, 2000, 04:47 AM
#6
New Member
This will hurt.
My friend,
You have run dead on into a brick wall, and instead of trying to find the door, you insist on smashing it down with your head.
Maybe you will succeed, but remember, whatever workaround Ram-optimizer fix patch job you do to your computer get it to work, you will have to require any body else who is going to use your program to do the same thing. Are people really going to run out and buy a super computer just to run your bloated, poorly designed ram-gobbling software?
I am sorry. I know you have spent a lot of time designing a program with 42 picture boxes and 120 line controls – it hurts to dump it all and start over. You should just stop. Take a break. Go to the beach. Relax. Think about ways to achieve your goals in a more economical manner. Then start over. The sooner you bite the bullet and get on with it, the sooner you will be done.
Rob
-
Mar 19th, 2000, 05:40 AM
#7
Lively Member
just an idea
create picture(0) at design time and then at runtime create the rest of your picture boxes (picture(1) - picture(41). Then before your program ends unload all the picture boxes you created at runtime(you cannot unload picture(0))
like i said, just an idea...
-
Mar 20th, 2000, 04:26 AM
#8
Thread Starter
Registered User
Something Wired...
Hey again..
Rob, Bman, and all who replied me and whoever reads this reply, Please tell me 1 thing:
Are Microsoft THAT dumb that they dont let the programmer to load 42 picture-boxes to the memory?!
Where are we? in the middle-ages?!?!
For all who wanted to know, I'm programming a backgammon game, so I need an array of 30 picture-boxes (15 for each opponent) + 12 cubes situations.
I also needed (and still need) 120 line controls because of a background problem. (which is not that easy to solve as it sounds).
If Microsoft's programmers who developed VB didnt want to think hard for a while and try to set the default useful VB controls to take the most less memory place, Why do they hire them?! Doesnt Bill Gates has enought money or what?!
Anyway, If you are new to this topic, Please reply your opinion, and try to help me solving the memory problem I have for months.
Thanks,
Lior, An Israeli Programmer.
-
Mar 20th, 2000, 04:37 AM
#9
Lively Member
This code should loop through every item that you have loaded and unload it. Is this what you are looking for?
Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim Thing As Variant
For Each Thing In Forms
Unload Thing
Next
End Sub
-
Mar 20th, 2000, 05:03 AM
#10
Frenzied Member
42 Picture boxes, you bloody madman!
Draw the background as a bitmap and load this to a std picture object, do the same for your pieces,dice and other stuff, 1 std picture for each. then on the forms paint event use the picture objects' render methods to draw the background and whatever else needs drawing, use command buttons below the little triangles to controll the moves, or if you want a drag effect us the form mousedon event to start dragging an invisible object, a shape or something, with a dragicon that looks like a piece. or use API methods to do something similar.
Hope this helps.
-
Mar 21st, 2000, 05:19 AM
#11
Thread Starter
Registered User
Damn!
God damn it, it still doesnt work! I'm going to kill myself any second!!!
Bsmith, thanks for trying to help me but even your piece of code didnt do the job.
Guys, All of you out there, PLEASE answer my ONE SIMPLE question:
I have a picture box array called: Blah(1 To 42)
I made an exit command button called: Command8
I just dont want my system resources to get to only 1% free!
THATS ALL !!!
What code should I put in the Command8 so it will just unload these 42 Picture-Boxes that are located in the array so it will NOT show me "OUT OF MEMORY" after every 10 times of running the project?!?!?!?!?
Or let me try to ask it more professionally:
How do I just unload a picture-box control which placed on the form at design-time?
Thats all...Please, if you know the answer to this simple question, Please reply.
Please do NOT try to convince me to change my attitude and to kill all of this picture-box array.
Thanks, And Still Waiting For Your Saving Answer,
Lior, An Israeli Programmer.
[Edited by Lior on 03-21-2000 at 05:43 PM]
-
Mar 21st, 2000, 01:48 PM
#12
Lively Member
As far as i know you cannot unload these picture boxes. That is why i suggested creating them at runtime. If you do this you will be able to loop through them and unload each one.
add a picture box, name it pbox
change pbox.index to 0
Code:
Private Sub form_unload(cancel As Integer)
Dim i As Long
For i = 1 To 41
Unload pbox(i)
Next i
End Sub
Private Sub Form_Load()
Dim i As Long
For i = 1 To 41
Load pbox(i)
pbox(i).Move 500, 500, 500, 500
pbox(i).Visible = True
Next i
End Sub
run this 10 times and see what happens
[
[Edited by _bman_ on 03-22-2000 at 02:36 AM]
-
Mar 21st, 2000, 08:45 PM
#13
Lively Member
I agree with _bman_. It will involve more work setting up your form, but if you start with Blah(0) on you form you can load Blah(1) through Blah(42). You will then be able to unload them.
-
Mar 21st, 2000, 09:39 PM
#14
Thread Starter
Registered User
...Still doesnt work
I tried to do what you said, i set the controls at run-time
and it really unloaded it.
BUT, although it doesnt take too much system resources, it is slow...i dont know why.
can it be because i have a lot of IF questions (about 200)
and a lot of FOR loops (about 1000 loops) ?
And anyway, If someone knows how to unload controls set on the form at design-time, Please tell me ans save my ass.
thanks.
Lior.
-
Mar 21st, 2000, 10:23 PM
#15
transcendental analytic
I agree with Sam Finch, there are way too many controls in your project. Now read: SEND ME THE PROJECT, and I will replace all UNNECCESARY CONTROLS with any graphical methods available. [email protected]
-
Mar 21st, 2000, 10:25 PM
#16
transcendental analytic
And as for your IFs and LOOPs, why?
-
Mar 21st, 2000, 11:23 PM
#17
Thread Starter
Registered User
here is the project
Guys,
if any1 wants the project, i put it online, the address is:
http://users.surfree.net.il/disconnector/BG.ZIP
few remarks:
1) the project is in hebrew, so dont be afraid of the unknown fonts
2) please unzip the file to the folder: C:\BG
it is required for the WAV files to be played.
Thats all...
please download the program, and if u think u can upgrade the code, please let me know.
Thanks,
Lior, An Israeli Programmer.
-
Mar 21st, 2000, 11:49 PM
#18
Junior Member
Alright - I've solved this one.
Get a cornflakes packet, a few buttons, a marker, a dice, and a ruler. Cut a square in the Corn-Flakes packet - this is your form (ask a grown-up for help with the scissors). Use the ruler to draw your lines and the marker for your picture boxes. To free space when finished - put it all under the couch.
I couldn't download that project. How did you do all those for-loops - do you have an automatic for-loop generation routine? I hope you have them commented.
-
Mar 22nd, 2000, 01:00 AM
#19
Thread Starter
Registered User
Very Funny, This is the best joke i've ever heard....I'm just going to cry, u idiot.
Man, I have a serious memory problem, and u make laugh, Are ya insane or what?!
by the way, I guess you dont know how to press on a URL link, because the BG.ZIP file IS there! I checked it.
(HELPFUL tip for you: just click on the blue text, that's all, really, I hope its not so complicated for you).
So guys,
ANY Ideads of how to unload control which placed on the from at design-time???
Hope to hear from the serious guys here,
Lior, An Israeli Programmer.
-
Mar 22nd, 2000, 01:05 AM
#20
Member
I think if you retry the _bman_'s suggestion, you should have no problems with properly unloading a control created at design time. Add this code to your form.
Public Sub Form_Unload(Cancel As Integer)
Unload Me
End Sub
That as I understand it will free up all memory used by that form.
This will only unload the current form, and will not stop execution of the program if there are other forms loaded. If there are other forms that you want to unload, try the following.
Public Sub Form_Unload(Cancel as Integer)
Dim frm as Form
For Each frm in Forms
Unload frm
Set frm = Nothing
Next frm
End Sub
I also agree with most other people though, and having this many controls on one form is not a good idea.
If you could clear one thing up for me. It sounds like you aren't having the trouble every time, but only after you have loaded the form multiple times. Is this correct? If so this method would unload the forms properly so that the next time you start it, it should be fresh.
Let me know if this helped
-
Mar 22nd, 2000, 01:30 AM
#21
transcendental analytic
What the heck are you trying to do? I downloaded your bg.zip and opened the main file and... Well I have no words for it. I think you have serious problems with doing the code. Im sorry but I can't help you, there's too many referings to the lines. And as for the For-nextloops and IFs, try to compress them a bit, i mean a lot. Try to use more Functions too.
-
Mar 22nd, 2000, 01:41 AM
#22
Frenzied Member
I agree with Sam Finch too.
-
Mar 22nd, 2000, 01:43 AM
#23
Junior Member
Hey,
I got your code and play around with it a bit, I have never play that game before so I have no idea what it is suppose to do (and with all those strange characters)...
well, at least I guess the exit aould be at the usual place in the menu... =)
There are things I want to comment on though,
1. put more comments in your code if you want people to help you (again, the strange characters)
2. start using prefixes for your variables (I know you name your variables with a readable name) but the prefix gives me an idea what type it is or the its scope (ie. a string variable "A" would be "strA")
3. I don't know what are all the triangles for, but if they are not going to be moved throughout the game, why not just draw the entire playing board out and load it as the background of the form (this saves you the 120 line controls)
4. I ran your program on a 128Mb machine, it works fine, but it slows down everything else after I quit it. Maybe there are some memory leak or things that are not unload entirely
5. I have not look at the way you load your wav file yet. But are youo loading them all at once? seems like you only need to play certain wav at certain time, load them on;y when you need it...
6. programming is a serious business. Have a little bit of patient and don't start bi*ching at people when they are not giving you the answer you want. go outside... clear your mind and Step through your code again, you might find something you've never suspect.
happy coding,
Cherith (Sparhawk)
-
Mar 22nd, 2000, 02:34 AM
#24
Junior Member
Picture Problem
Unfortunately, I have been plagued with your problem too. To fix mine, I used Image Boxes, which helps a lot. You can also make the pictures as a Control Array which an also bite down on the RAM usage. When you unload the program..just use Unload Me, or Unload "Yourform" (get rid of the ""). Or you can just seperate the pictures into different forms.
-
Mar 22nd, 2000, 03:10 AM
#25
transcendental analytic
I took a deep breath and searched for the big ? in your code. Im not finished yet but here's how to remove the 120 linecontrols:
Remove the green line in the form.
in the Private Sub LoadAllControls()
Remove Everything from
" For A = 1 To 120 ' load the lines for drawing the triangles "
to
"End Sub"
And replace it with:
For AY = -1 To 1 Step 2
For AX = 0 To 1
For BX = 0 To 5
For CX = 0 To 4
Line (AX * ScaleWidth / 2 + BX * 600 + CX * 120 + 60, (AY + 1) / 2 * ScaleHeight)-(AX * ScaleWidth / 2 + BX * 600 + 300, ScaleHeight / 2 + AY * 600), RGB(127 * ((BX + (1 + AY) / 2) Mod 2), 0, 0)
Next CX
Next BX
Next AX
Next AY
End sub
Then declare the vars AY,AX,BX and CX as integers. Don't replace them with the A,B,C,D you have to learn to name your vars functionally.
This will definitly free up some resources for you. The colors are now black and red, but you can change the algoritm in the RGB function.
Hope this works!
-
Mar 22nd, 2000, 03:24 AM
#26
Lively Member
If statments
if your using alot of if statments your code will run slow... I would make case statments to do this instead... That way you can one just for more objects and 2 it will run faster..
Just my $0.2
-
Mar 22nd, 2000, 03:53 AM
#27
Thread Starter
Registered User
A few remarks about my massive project
Guys Guys,
Look, I am writing this reply when I didnt test your suggestions from my last reply yet.
but i want some things and facts to be more clear:
1) Dont be afraid of these strange characters, the project is coded for the Hebrew speakers, do i guess you dont have the right fonts, and even if u have hebrew fonts, how many of you know Hebrew? Hebrew is my mother-language.
2) A,B,C,D are just temporary-helping-variables.
All of the other variable named with a special name
that says their stand for.
3) I didnt use functions by now, because I didnt need them
yet. I'm sure I will use functions in the next develop- Step, when the computer will have to think on the right
move again the human-player.
(For those who knows how to play the BackGammon Game)
4) I didnt use Image-Boxes because I'm not sure you can
drag them using the MouseDown,MouseMove,MouseUp events.
5) I will try your suggestions right now, the code for the
lines, and the "Unload Me".
Although I think I already tried something like:
"Unload MainForm". I'm not sure the "Unload Me" will
unload the controls made at design-time, But I will try.
6) That's all for now, I'm going to check your suggestions
now. I will reply again in about 1 hour from now.
(I want to test your suggestions very hard).
Thanks again for your suggestions,
Lior, A desperated Israeli programmer that has been given
a hope by all of you.
-
Mar 22nd, 2000, 04:50 AM
#28
Thread Starter
Registered User
I tried your suggestions and...
Guys,
I checked your suggestions and I tried 3 things:
1) I tried the "Unload Me" when the controls were made at
design-time, and It really didnt steal any system
resources, BUT is slowed down the whole system after 4
times of running the compiled EXE !!
2) I switched all of the controls to be created at run-time
and then I tried the "Unload Me" - I got the same result:
No system resources stole, but the WHOLE system was
very very very slowed down after about 4 times of
running the EXE.
3) I tried Kadaman's method, to replace the 120 line
controls with Line Method, Well Kadaman, The code you
wrote was not ok in my project, BUT you gave me a great
idea!!! you saved me from loading 120 Line Controls!
REAL THANKS. The time now here in Israel is over
midnight, so I guess I will handle this tommorow.
4) When I ran the EXE and found out if slows down the
system terribly, I tried to delete the EXE through
DOS window, I got the error message: "Access Denied".
It's because the program is still existing in the memory.
Does some1 know how to terminate an open program?
5) I was thinging of trying to use the Image-Boxes Instead
of the Picture-Boxes, But, I am not sure image boxes are
draggable, I will try it tommorow, The time now is 2 AM.
Good Night (for the people who are going to sleep now),
And Try answer my question.
Thanks Again,
Lior. An Israeli Programmer.
-
Jun 19th, 2000, 03:46 AM
#29
Junior Member
I know you are on your way with this project, but i was wondering about your drag and drop problem. My question was, why bother trying to drag and drop picture-boxes or images? Why not try something like an image map. track your cursor position using the getCursorPos api and then check for a mouse down and track the cursor position until the mouseup and then redraw your game piece at that location. that way, you can have just the one gamepiece in a picture box and just redraw as many times as neccesary. i am just about positive that you won't have ANY sort of memory allocation problems. plus your game play will be much faster and maybe a little more intuitive also.
just my opinion!
Shaheeb
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|