Mem usages rises and falls

Started by
10 comments, last by VanillaSnake21 15 years, 7 months ago
Hi, I'm making an application with some directX components and some windows components. The problem is that when i just open the application the Mem Usage in the Task Manager reads something like 37,000 K then it keeps rising and rising and the suddenly falls to something like 1,190 K. Anyone has any idea on why that happens.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
At a wild guess, I'd say because something in your program allocates around 36MB of memory, and then frees it.

Given that we know nothing about your program, I don't know if you were expecting more detailed answers.
Quote:Original post by Spoonbender
At a wild guess, I'd say because something in your program allocates around 36MB of memory, and then frees it.

Given that we know nothing about your program, I don't know if you were expecting more detailed answers.


Right, sorry for the vague question, the app is pretty simple and it all fits within about 100 lines but I'm using custom functions which span into thousands of lines, so posting code wouldn't be that usefull.
Any ways by the means of good ol' comment-stuff-out method I managed to get the program to load at 13K and just sit there, which is fine. I have a couple of questions though about the whole memory management thing. Is there any way I can monitor how much memory my program allocates, especially if I'm dealing with another API (So for example I have no idea what the DirectX functions I'm calling are allocating in the background). Another thing I've been thinking about is garbage collection. I have a couple of really good books that tell me how to implement this, and there is a helpful resouce on this site as well. Do you think it is necessary in game development, and do it's benefits outweigh it's compromises (precisely, the overhead for collecting all the loose pointers). What do you guys think?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

I think garbage collection in C++ is such a pain, and so tricky to get right, that you're better off without it. Unless, perhaps, you're dealing with legacy code which leaks memory left and right.

However, I'm not sure I see why it's such a problem that the functions you call allocate memory?
Quote:Original post by Spoonbender
I think garbage collection in C++ is such a pain, and so tricky to get right, that you're better off without it. Unless, perhaps, you're dealing with legacy code which leaks memory left and right.

However, I'm not sure I see why it's such a problem that the functions you call allocate memory?


Thats no problem at all, but since the program started at 30,000K and over a minute escalated to 100,000K then i figured i was calling "new" in some loop. (And so I was, I was rebuilding a string without releasing the previous memory). I do agree that a garbage collector is no easy task to achieve, and I'm not really that enthusiastic as to start writing one, but like I said previously, I want to know exactly how much memory my app allocated. Wouldn't the GC allow me to do that? I can modify it to where it wont collect garbage but just monitor how much memory is currently used. Or is there a better approach to it? Thanks

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Quote:Original post by VanillaSnake21
I was rebuilding a string without releasing the previous memory

By "string", do you mean a char* or a std::string?
Instead of garbage collection, you might want to look into tracking your allocations. It's not too difficult to overload global operator new and track them. If you're using Visual Studio then VLD will do it for you, it'll even tell you the call stack for each leak.
Task manager has two columns, Mem Usage and VM Size. You need to watch both.

It's not a reliable indication anyway, especially when using OS API.
Quote:Original post by VanillaSnake21
Hi, I'm making an application with some directX components and some windows components. The problem is that when i just open the application the Mem Usage in the Task Manager reads something like 37,000 K then it keeps rising and rising and the suddenly falls to something like 1,190 K. Anyone has any idea on why that happens.
Task Manager isn't at all accurate, particularly when using DirectX stuff. The "Mem Usage" doesn't mean what you might think, it's the processes working set size.
DevFred
Quote:
By "string", do you mean a char* or a std::string?

char*

Adam_42
Quote:
Instead of garbage collection, you might want to look into tracking your allocations. It's not too difficult to overload global operator new and track them. If you're using Visual Studio then VLD will do it for you, it'll even tell you the call stack for each leak.

This is pretty impressive, I didn't even know that such a plugin existed, Thanks, I'll definitely try it out.

@Antheus & Evil Steve
I know TM isn't the best way to track memory allocation, but it lets me know if theres a significan leak somewhere (like what I had before, with the new in a loop).

Thanks for the replies everyone






You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

This topic is closed to new replies.

Advertisement