Memory problem

BlitzMax Forums/BlitzMax Beginners Area/Memory problem

Ferret(Posted 2006) [#1]
Hi,

I have problems releasing memory.
If i remove Flushmem from the example it leaks memory.
Removing the image is not releasing the memory.

Global img

Graphics 800,600,0,75
While Not KeyHit(Key_Escape)

If KeyHit(Key_Space) Then img = LoadImage("media/gui/splash01.png")
If KeyHit(Key_Return) Then img = 0

If img Then DrawImage(img,100,100)

DrawText "MemAlloc: " + MemAlloced(),10,10
DrawText "MemUsage: " + MemUsage(),210,10


Flip
Cls
FlushMem()
Wend

End


Thx


Diablo(Posted 2006) [#2]
your are loading an image in a loop which would explain mem leak, but which is also extremely bad practice.

Also what version of blitzmax are you running... you should make sure your have the latest version which is 1.18
. A link can be found at the top of the forum page.

oh and i think it should be '= Null' and not '= 0'


Dreamora(Posted 2006) [#3]
You need to update to 1.18, there the problems are fixed.

The mem commands clearly state that you have a quite outdated version ...


Yan(Posted 2006) [#4]
You're making BMax do an object to integer handle conversion so you must release the handle when you've finished with it...
Global img

Graphics 800,600,0,75

While Not KeyHit(Key_Escape)

	If KeyHit(Key_Space)
		Release img
		img = LoadImage("media/gui/splash01.png")
	EndIf
	
	If img Then DrawImage(img,100,100)
	
	DrawText "MemAlloc: " + MemAlloced(),10,10
	DrawText "MemUsage: " + MemUsage(),210,10
	
	
	Flip
	Cls
	
	FlushMem()

Wend

End


You should be using a later version of BMax and try to use objects rather than integer handles as it allows BMax to handle most of the memory management for you...
Strict

Local img:TImage

Graphics 800,600,0,75
While Not KeyHit(Key_Escape)
	Cls
		
	If KeyHit(Key_Space) Then img = LoadImage("media/gui/splash01.png")
	
	If img Then DrawImage(img,100,100)
	
	DrawText "MemAlloc: " + MemAlloced(),10,10
	DrawText "MemUsage: " + MemUsage(),210,10
	
	
	Flip
	FlushMem
Wend

End



Ferret(Posted 2006) [#5]
Ok, i updated to 1.18, thx for pointing that out to me.

But, this gives me a new problem.
It fails to import the mappy mod giving me this error, "Can't find interface for module 'pub.mappy'"


Dreamora(Posted 2006) [#6]
Delete the .a and .s in pub.mod/mappy.mod and recompile all modules. Then it will work again :)


Ferret(Posted 2006) [#7]
I love this comunity, always solves mi problems ;)

I will have a closer look at objects once i get mappy to work again.

About recompiling, all modules or the mappy ones? And what do i use to compile them, Bmax??


Diablo(Posted 2006) [#8]
if you are on windows you will need this or this. and then open the ide and press ctrl+d

And what do i use to compile them, Bmax??

yes.


Ferret(Posted 2006) [#9]
I am on windows but those links give me "internal erorr" page.


Diablo(Posted 2006) [#10]
wired.. one should be blitzmax and the other on blitzbasic.. what site are you loged on?

anyways, heres a more direct link..
http://prdownloads.sourceforge.net/mingw/MinGW-3.1.0-1.exe?download

you will need to download then install this, and then follow these instructions...

AFTER INSTALL
* Edit your PATH environment to include the MinGW/bin directory.

* Create a MINGW environment variable that points to the MinGW root directory.


if you need to know how to edit you PATH environment, etc.

* right click 'my computer' on the dektop (or browse to 'my computer' and then right click that) and click 'properties'.

* click the tab named 'advance' and then click the button 'environment variables'.


Ferret(Posted 2006) [#11]
I found the posts you linked to but i must be doing something wrong.

I made a new variable with "MinGW" as name and "C:\MinGW" as value, is this correct?


Damien Sturdy(Posted 2006) [#12]
Did you install MinGW into "C:\MinGW"?


Diablo(Posted 2006) [#13]
^check that first

it should be. Then open up blitzmax and press ctrl+d

.. if you click the menu 'Program', 'Build Modules' should be clickable.


Ferret(Posted 2006) [#14]
MinGW is installed in "C:\MinGW"

I keep getting the build error.

1. uninstalled Bmax
2. deleted the Bmax dir
3. installed Bmax 118

4. instaled MinGW
5. made a new variable with "MinGW" as name and "C:\MinGW" as value
6. Ctrl+d to rebuild all modules

7. Build Error: failed to compile C:/Program Files/BlitzMax/mod/brl.mod/blitz.mod/blitz_app.c

What did i do wrong?


Diablo(Posted 2006) [#15]
did you:
* Edit your PATH environment to include the MinGW/bin directory.

- not sure if you have todo this, but its worth a shot.


Ferret(Posted 2006) [#16]
How do i do that?


Diablo(Posted 2006) [#17]
go to the place were you created the MinGW variable and look for a variable called 'path', double click it and then at the end of the text add ';MinGW/bin'

It will be on the bottom of the two lists.


assari(Posted 2006) [#18]
Whilst you are trying to sort out your compile problems, here is a mappy module that works w 1.18. Download Here
You need to extract the zipped files into pub.mod


Ferret(Posted 2006) [#19]
Problem solved, thank you all.

I'm able to compile modules now, and installing 1.18 solved mi memory problem.