Jump to content
  • Advertisement
Sign in to follow this  
newbie123

[Solved]Allegro Game taking 300mb of RAM !

This topic is 2703 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi guys

so i'm making sort of Engine / game kind of thing and i noticed when i open the game it takes about 300MB of RAM !!! WHY ??!!!

if i initialize BITMAP a lot does that take from my RAM ?

also i dont use destroy BITMAP function does that has to do with the high memory usage ?

i know that if you dont destroy bitmap it only takes from the GPU RAM not the main RAM

thankx

Share this post


Link to post
Share on other sites
Advertisement
Generally speaking, if you allocate dynamic resources that are intended to be freed, but don't free them, that can cause a memory leak. If you're doing this often (e.g. every frame), then it might result in the kind of memory usage you're seeing.

Share this post


Link to post
Share on other sites

i know that if you dont destroy bitmap it only takes from the GPU RAM not the main RAM[/quote]
Not necessarily true. It depends on the exact combination of lower level APIs in use. Also some graphics cards "steal" RAM to use as video memory (though that will probably show up in a different way).

Share this post


Link to post
Share on other sites

Generally speaking, if you allocate dynamic resources that are intended to be freed, but don't free them, that can cause a memory leak. If you're doing this often (e.g. every frame), then it might result in the kind of memory usage you're seeing.


i'm sorry but i didn't quite understand, what do you mean by "if you allocate dynamic resources that are intended to be freed, but don't free them"
how can i free resources?
and i noticed that when starting the game it only uses 20MB and after a while it reaches 300MB and more

how can i solve this memory leak ?

thankx for the post :D

Share this post


Link to post
Share on other sites

how can i free resources?

It depends on the resource.

What language are you programming in? And is BITMAP an Allegro type, or something else?

Share this post


Link to post
Share on other sites

how can i free resources? how can i solve this memory leak ?


By pairing a delete[] for every new[], a delete for every new, and a destroy_bitmap for every create_bitmap, load_bitmap, and any other Allegro API function that reminds you "that you are responsible for destroying the bitmap when you are finished with it to avoid memory leaks".

Share this post


Link to post
Share on other sites

[quote name='newbie123' timestamp='1303833642' post='4803115']
how can i free resources?

It depends on the resource.

What language are you programming in? And is BITMAP an Allegro type, or something else?
[/quote]

i'm using C++ and Allegro Graphic Library.
BITMAP is like a function that passed a pointer to a specific file

Example BITMAP *GameBackGround = load_bitmap ("background.bmp",NULL);


[quote name='newbie123' timestamp='1303833642' post='4803115']
how can i free resources? how can i solve this memory leak ?


By pairing a delete[] for every new[], a delete for every new, and a destroy_bitmap for every create_bitmap, load_bitmap, and any other Allegro API function that reminds you "that you are responsible for destroying the bitmap when you are finished with it to avoid memory leaks".
[/quote]

ok thankx i'll try destroy all the bitmaps.
this is going to take a while LOL :D

Share this post


Link to post
Share on other sites
OK new problem
every time i use "destroy_bitmap(Buffer);" , i get an error "0xC0000005:Access violation reading location 0xfeeefefe"
btw i have a player class which is like this


// player class in hader file called player
class Player
{
public:
Player();
~Player();
void Init();
void Draw(BITMAP *Buffer);
void Health();
void Attake();
void Hurt();
bool Is_Dead();
void Keyboard(BITMAP *Buffer);
void Mouse(BITMAP *Buffer);
bool PlayerDead;

int x , y , MouseX, MouseY , imgx , imgy , PlayerHealth;
BITMAP *Hero_char;
};

------------------------------------------
//then there is a draw class in a new header file called Draw

class Draw
{

public:
Draw();
~Draw();
void Init();
void GameOver(BITMAP *Buffer);
void NPC_fun(BITMAP *Buffer);
BITMAP *Buffer , *GameOverScreen , *NPC;

};


i have both header file and c++ file.
i tried destroy Buffer in Main.cpp but that gave me the error i told you about above
also should i destroy the Buffer in Main.cpp ? in the game loop ? because thats what i di.
also where do i destroy *GameOverScreen , *NPC , *Hero_char; ? should i destroy them also in main or at the end of their own class ?

Share this post


Link to post
Share on other sites
To begin with, if the BITMAP (or a similar resource) is a member of a class, you should free the resource in the destructor for that class. (There are ways to automate this process, but simply freeing the resource in the destructor would be a good start.)

Share this post


Link to post
Share on other sites

To begin with, if the BITMAP (or a similar resource) is a member of a class, you should free the resource in the destructor for that class. (There are ways to automate this process, but simply freeing the resource in the destructor would be a good start.)


how stupid of me, how didnt i think of that LOL
great thankx

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!