• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Nickie

Strange Memory Leaks...

8 posts in this topic

So I decided the check the memory usage of my program. I ran it and opened win7's resource manager.
I noticed the memory usage is incresed by 200 kb each second. Is it normal?
I actually have many tiny allocation on runtime(I know it is bad idea, thats why I've got plan B if it eat too much performance later)
Also MSVC is telling me I have maaaanyyyyy memory leaks.
[url="http://pastebin.com/hzHb4vSp"]http://pastebin.com/hzHb4vSp[/url]
I checked all my code. All new's I have ever used in this project are in std::tr1::shared_ptr. Except one but I double checked it, it is beeing freed when it is time.
Maybe my singletons(I have 2 global singletons -> Event Manager and String manager) and freed later? Actually where are they released? Their objects are in shared_ptrs.

Or I haven't used the right macros?
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
this is at the beginning of my main.h(right after pragma once)

_CrtDumpMemoryLeaks(); this is right before return;

I've seen this code:
#define new new (_FILE_, _LINE_, _LINE);
or something like this. I don't have such thing. What is it beeing used for? Is it required?


PS. I'm thinking of possible memory fragmentation. I have something like 4-5 new for 8-16 bytes each frame. I also destruct them the same frame or the next. Is it possible? Edited by Nickie
0

Share this post


Link to post
Share on other sites
Actually I though about this. It is possible only in my hierachies. (parent + child ptrs)
And still it is telling me for large amout of leaks. But I've got idea. I'll record their count(or lines) and then put manual destruction of the hierarchies. And then I'll see if there is difference.
0

Share this post


Link to post
Share on other sites
Ok. I fixed my destruction method of the hierarchies. -500 lines of memory leaks. Still 2000 left. Hmh.. I'll review my whole design for more of these circulars, however it will take time. I'll write here as soon as I'm done. Thanks.(I hope there won't be memory leaks after fixing them [img]http://public.gamedev.net//public/style_emoticons/default/tongue.png[/img])


I managed to take the memory leaks to 400 lines. I was actually right. It is thinking about my globals as memory leaks.
I have made a table like this:
ID, STRING, REF Count
And I'm actually keeping just the id in the strings. This gives really fast comparing.
And I have made for example a new actor event:

static const RE_String new_actor = "NewActor"; // this way the lookup for id is done just once at init

Strange. Maybe here comes this? What is beeing used for?:
[quote]I've seen this code:
#define new new (_FILE_, _LINE_, _LINE);[/quote]
Any suggestions? Edited by Nickie
2

Share this post


Link to post
Share on other sites
Maybe you should use Valgrind or Deleaker for detecting memory leak? [img]http://public.gamedev.net//public/style_emoticons/default/rolleyes.gif[/img]
2

Share this post


Link to post
Share on other sites
[quote name='Nickie' timestamp='1347279325' post='4978550']Strange. Maybe here comes this? What is beeing used for?:
[quote]I've seen this code:
#define new new (_FILE_, _LINE_, _LINE);
[/quote]
Any suggestions?[/quote]

This macro tags all of your "new" with additional information -- the file and the line wherein the allocation was made. (Though, it should be [tt]new (_NORMAL_BLOCK, __FILE__, __LINE__)[/tt].) If you haven't already, take a look at the [url=http://msdn.microsoft.com/en-us/library/x98tx3cf%28v=vs.100%29.aspx]documentation on MSDN[/url] on the subject. It is also important to note that a [tt]#define[/tt] in one header file isn't neccessarily applied everywhere else to your project. Remember, the contents of a header file are dumped into the source file that includes it and each source file is compiled separately. If you have one source file that includes a set of headers that eventually defines the [tt]new[/tt] macro and another source file that does not, then allocations with [tt]new[/tt] in the first file will get logged with the additional information and the other source will not. Edited by fastcall22
2

Share this post


Link to post
Share on other sites
So... The guy who posted the links for deleaker. Thank you. I was albe to fix my memory leaks alone. However. using deleaker I found that most of the leaks are comming from DXUT. This means that my program is not behaving correctly on lost/reset/create device/etc. There are my problems comming from. Gonna check the samples DXSDK is comming with. I think I'm destorying the resources in a wrong callback(if I didn't do it anythwere DXUT whoud popup a leak message).


[CODE]
#include <memory>
#include <iostream>
std::string almost_undetectable_memory_leak = "hello world!";
int main()
{

_CrtDumpMemoryLeaks();
return 0;
}
[/CODE]

[CODE]
Detected memory leaks!
Dumping objects ->
{143} normal block at 0x00654E68, 8 bytes long.
Data: < 5 > A0 D1 35 01 00 00 00 00
Object dump complete.
[/CODE]

How to avoid these messages, so I can find the real leak? I'm sure these strings are released... Edited by Nickie
0

Share this post


Link to post
Share on other sites
[quote name='Nickie' timestamp='1347357047' post='4978842']<br />How to avoid these messages, so I can find the real leak? I'm sure these strings are released...[/quote]

It is, just not at before [tt]_CrtDumpMemoryLeaks[/tt] is called. [tt]almost_undetectable_memory_leak[/tt] is destroyed after [tt]main[/tt] returns. To solve: restrict all objects to the tightest scope allowed -- avoid global objects (and by doing so, you'll avoid the static initialization order fiasco as well).
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0