Releasing Memory when finished using CreateLine3D
Releasing Memory when finished using CreateLine3D
I'm trying to figure out how to release the memory on a 3D Line after you've finished using it. I've tried using FreeMesh() on them, but it doesn't appear to release them.
If you guys need my code I'll post it later when i have more time. Thanks.
If you guys need my code I'll post it later when i have more time. Thanks.
Re: Releasing Memory when finished using CreateLine3D
it can helpSamuel wrote:If you guys need my code I'll post it later when i have more time.
Please correct my english
http://purebasic.developpez.com/
http://purebasic.developpez.com/
Re: Releasing Memory when finished using CreateLine3D
OK i created a little example of my problem. When i first start up this program it uses about 146,000K of memory. If you Press and Release ENTER you should see a white square of 600 3D Lines. The memory usage for me jumped up to about 151,500K. If you Press and Release ENTER again it will delete the 600 lines, but my memory only returns to about 151,000K of memory. Now normally i wouldn't be concerned by this, but I'm creating a program that does a lot of wireframe drawing. So its deleting and drawing 3D lines a great deal. Overtime this causes a good chunk of memory to be used. Any help is greatly appreciated as always.
Code: Select all
;**************************************************************
;********PRESS ESCAPE TO EXIT**********************
;**************************************************************
ExamineDesktops()
If InitEngine3D()
Else
MessageRequester("Information", "ERROR///Could not InitEngine3D", 0)
End
EndIf
If InitSprite()
Else
MessageRequester("Information", "ERROR///Could not InitSprite", 0)
End
EndIf
If InitKeyboard()
Else
MessageRequester("Information", "ERROR///Could not InitKeyboard", 0)
End
EndIf
Dim Line3DHandles(700)
DeskWid=DesktopWidth(0)-200
DeskHei=DesktopHeight(0)-200
If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
CreateTexture(2, 512, 512)
StartDrawing(TextureOutput(2))
Box(0, 0, 512, 512 ,RGB(255,100,20))
StopDrawing()
CreateMaterial(3, TextureID(2))
MaterialAmbientColor(3, RGB(0,0,0))
CreatePlane(3, 30000, 30000, 100, 100, 100, 100)
CreateEntity(3,MeshID(3),MaterialID(3), 0, -1000, 0)
CreateLight(0, RGB(250, 250, 250), -100, 100, 200)
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 0, 0, 1250)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(55, 55, 55))
Repeat
Event = WaitWindowEvent(0)
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Return)
If Click=1
Gosub Remove3DLines
EndIf
If Click=0
Gosub Draw3DLines
EndIf
EndIf
EndIf
RenderWorld()
FlipBuffers()
Delay(10)
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
End
;-Draw3DLines
Draw3DLines:
SX=-300
SY=300
EX=300
EY=300
Next3DLine:
CreateLine3D(LineCTR, SX, SY, 0, RGB(255,255,255), EX, EY, 0, RGB(255,255,255))
Line3DHandles(ArrayCTR)=LineCTR
LineCTR=LineCTR+1
ArrayCTR=ArrayCTR+1
SY=SY-1:EY=EY-1
If LineCTR=600
Goto FinishDrawingLines
Else
Goto Next3DLine
EndIf
FinishDrawingLines:
Click=1
Return
;-Remove3DLines
Remove3DLines:
RemoveNext3DLine:
FreeMesh(Line3DHandles(CurrentLine))
CurrentLine=CurrentLine+1
If CurrentLine=600
Goto FinishRemovingLines
Else
Goto RemoveNext3DLine
EndIf
FinishRemovingLines:
Click=2
Return
Re: Releasing Memory when finished using CreateLine3D
Thats nothing. Don't trust the Task Manager. And don't expect Windows
to just release memory if you call "freememory". Memoryhandling is a
little bit more then that.
And ... please next time if you post code, don't use gosub ... especially
for loops.
Run this and click return multiple times ... memory will not rise constantly 
to just release memory if you call "freememory". Memoryhandling is a
little bit more then that.
And ... please next time if you post code, don't use gosub ... especially
for loops.
Code: Select all
;**************************************************************
;********PRESS ESCAPE TO EXIT**********************
;**************************************************************
EnableExplicit
Define.i SX = -300
Define.i SY = 300
Define.i EX = 300
Define.i EY = 300
Define.i Y.i, Y2.i, Click.i = 0
Define.i DeskWid, DeskHei, Event
NewList Line3DList.i()
ExamineDesktops()
If InitEngine3D()
Else
MessageRequester("Information", "ERROR///Could not InitEngine3D", 0)
End
EndIf
If InitSprite()
Else
MessageRequester("Information", "ERROR///Could not InitSprite", 0)
End
EndIf
If InitKeyboard()
Else
MessageRequester("Information", "ERROR///Could not InitKeyboard", 0)
End
EndIf
Dim Line3DHandles(700)
DeskWid=DesktopWidth(0)-200
DeskHei=DesktopHeight(0)-200
If OpenWindow(0, 0, 0, DeskWid, DeskHei, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget)
If OpenWindowedScreen(WindowID(0), 0, 0, DeskWid, DeskHei, 0, 0, 0)
CreateTexture(2, 512, 512)
StartDrawing(TextureOutput(2))
Box(0, 0, 512, 512 ,RGB(255,100,20))
StopDrawing()
CreateMaterial(3, TextureID(2))
MaterialAmbientColor(3, RGB(0,0,0))
CreatePlane(3, 30000, 30000, 100, 100, 100, 100)
CreateEntity(3,MeshID(3),MaterialID(3), 0, -1000, 0)
CreateLight(0, RGB(250, 250, 250), -100, 100, 200)
CreateCamera(0, 0, 0, 100, 100)
CameraLocate(0, 0, 0, 1250)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(55, 55, 55))
Repeat
Event = WaitWindowEvent(0)
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_Return)
If Click = 1
ForEach Line3DList()
FreeMesh(Line3DList())
Next
ClearList(Line3DList())
Else
Y2 = EY
For y = SY To SY - 600 Step -1
AddElement(Line3DList())
Line3DList() = CreateLine3D(#PB_Any, SX, Y, 0, RGB(255,255,255), EX, Y2, 0, RGB(255,255,255))
Y2 = Y2 - 1
Next
EndIf
Click = 1 - Click
EndIf
EndIf
RenderWorld()
FlipBuffers()
Delay(10)
Until KeyboardPushed(#PB_Key_Escape)
EndIf
EndIf
EndRe: Releasing Memory when finished using CreateLine3D
OK, I tried the code and your right about that. So thanks for the help. As for the subroutines not being in loops. I'm curious if that's just what you prefer or if there's a good reason why i shouldn't use them? I'll stop using them if that's what most people prefer or if its incorrect, but I've never had problems in the past with them in my code. Thanks again for the help.
Re: Releasing Memory when finished using CreateLine3D
Hi Samuel
using Goto, Gosub, is a famous and huge debate, personally i use goto when i am hurry, but if a programmer have used Goto or Gosub in a programming company he will be dismissed for sure. look for this sentence "I've never had to use a goto in C++. Ever. EVER" in this talk "To Use GOTO or Not?" http://stackoverflow.com/questions/3791 ... oto-or-not
why exactly google for the huge documetation about that.
they said "The structured program theorem proved that the goto statement is not necessary to write programs" look http://en.wikipedia.org/wiki/Goto
for more info google "using Goto"
using Goto, Gosub, is a famous and huge debate, personally i use goto when i am hurry, but if a programmer have used Goto or Gosub in a programming company he will be dismissed for sure. look for this sentence "I've never had to use a goto in C++. Ever. EVER" in this talk "To Use GOTO or Not?" http://stackoverflow.com/questions/3791 ... oto-or-not
why exactly google for the huge documetation about that.
they said "The structured program theorem proved that the goto statement is not necessary to write programs" look http://en.wikipedia.org/wiki/Goto
for more info google "using Goto"
Re: Releasing Memory when finished using CreateLine3D
Thanks for the information applePi.
I wasn't aware of all the dislike for gotos and gosubs. I suppose i learned a very incorrect way of programing. I'll have to start correcting myself and try to do it more properly. I guess that's the process of learning. Thank you again for the links and info.
I wasn't aware of all the dislike for gotos and gosubs. I suppose i learned a very incorrect way of programing. I'll have to start correcting myself and try to do it more properly. I guess that's the process of learning. Thank you again for the links and info.
Re: Releasing Memory when finished using CreateLine3D
when I was a kid, my cousin had a fancy nut cracker, looked cool, broke the nuts well and you could get to the meat inside . Me, I used my dads hammer, had the same effect, though sometimes it sent pieces flyin everywhere.
So, whatever you are comfortable with, do it, long as you get your nuts in the end!
Heard the same argument about Arrays VS Types, use whichever you like, they both store numbers, they both work in modern languages , and when people run your program once its compiled and turned into an Exe, they'll never know the difference.
Purebasic, because other languages are just babble!!
So, whatever you are comfortable with, do it, long as you get your nuts in the end!
Heard the same argument about Arrays VS Types, use whichever you like, they both store numbers, they both work in modern languages , and when people run your program once its compiled and turned into an Exe, they'll never know the difference.
Purebasic, because other languages are just babble!!
Re: Releasing Memory when finished using CreateLine3D
Thanks for the advice. I'm trying to learn the more "professional" way, but mainly for when I post code on the boards. That way its easier for others to follow.
On my own programs, that are only seen by me, I'll use whatever gives me a better result. If they both tend to give me the same result then I'll just go with whats faster to put together. After all spare time means spare programs.
On my own programs, that are only seen by me, I'll use whatever gives me a better result. If they both tend to give me the same result then I'll just go with whats faster to put together. After all spare time means spare programs.
Re: Releasing Memory when finished using CreateLine3D
You should certainly try to code without gotos and take advantage of all the features available in a structured language, gotos are often a bad idea.Samuel wrote:Thanks for the advice. I'm trying to learn the more "professional" way, but mainly for when I post code on the boards. That way its easier for others to follow.
But only often, not always. A good programmer should be able to discern when a goto could not only be useful, but a lot better than a structured mess.
A couple of the many posts you can find written by me on this subject:
http://www.purebasic.fr/english/viewtop ... 24#p374524
http://www.purebasic.fr/english/viewtop ... 50#p330250
Gotos can help to produce cleaner, better understandable code, easier to mantain, especially in languages like PB or C. it's equally bad when you see a goto used inappropriately as when you don't see one used in the right place.
"Have you tried turning it off and on again ?"
Re: Releasing Memory when finished using CreateLine3D
Thanks for the links to your posts. The first type of Basic that I had only allowed gotos and gosubs. So I got into the habit of using them, but avoiding them does make things a lot easier to follow and debug. From now on I'll try to avoid them and only use them when and if necessary.


