Increase memory usage when creating new devices

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
carlosgc
Posts: 5
Joined: Wed Nov 14, 2007 5:26 pm

Increase memory usage when creating new devices

Post by carlosgc »

I'm doing some tests with memory and device creation. My code create a new device after destroy the running one. The memory usage increases after each createDevice, even if the device->drop method is called before.

That is my code:

Code: Select all

int main()
{
	IrrlichtDevice *device;
	IVideoDriver* driver;
	ISceneManager* smgr;
	IGUIEnvironment* guienv;
	ICameraSceneNode *cam;

	while(true)
	{
		device =
			createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(800, 600), 32,
				false, false, false, 0);

		device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

		driver = device->getVideoDriver();
		smgr = device->getSceneManager();
		guienv = device->getGUIEnvironment();

		guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
			rect<int>(10,10,260,22), true);

		cam = smgr->addCameraSceneNode(0, vector3df(50, 50, 50), vector3df(0, 0, 0));

		while(device->run())
		{
			driver->beginScene(true, true, SColor(255,140,100,101));

			driver->endScene();
		}

		smgr->getRootSceneNode()->removeAll();
		driver->removeAllTextures();
		guienv->clear();
		device->drop();
	}

	return 0;
}
Is it normal? Is it a bug? Are there anything that could be done to not increase memory usage?
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Can you be more specific about how you're tracking the rising memory usage? I'm doing this, on Windows:

Code: Select all

#include <irrlicht.h>

#include <windows.h>
#include <psapi.h>


using namespace irr;
using namespace core;
using namespace video;
using namespace scene;
using namespace gui;

#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "psapi.lib")

int main()
{
   IrrlichtDevice *device;
   IVideoDriver* driver;
   ISceneManager* smgr;
   IGUIEnvironment* guienv;
   ICameraSceneNode *cam;

   FILE * log = fopen("log.txt", "w");
   for(int iteration = 0; iteration < 100; ++iteration)
   {
      device =
         createDevice( video::EDT_DIRECT3D9, dimension2d<s32>(800, 600), 32,
            false, false, false, 0);

      device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo");

      driver = device->getVideoDriver();
      smgr = device->getSceneManager();
      guienv = device->getGUIEnvironment();

      guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
         rect<int>(10,10,260,22), true);

      cam = smgr->addCameraSceneNode(0, vector3df(50, 50, 50), vector3df(0, 0, 0));

      while(device->run())
      {
         driver->beginScene(true, true, SColor(255,140,100,101));
         driver->endScene();

         device->closeDevice();
      }

      smgr->getRootSceneNode()->removeAll();
      driver->removeAllTextures();
      guienv->clear();
      device->drop();


       PROCESS_MEMORY_COUNTERS counters;
      (void)GetProcessMemoryInfo(GetCurrentProcess(), &counters, sizeof(counters));

      fprintf(log, "WSS %d \tPWSS %d\tPFU %d\tPPFU %d\n",
          counters.WorkingSetSize,
          counters.PeakWorkingSetSize,
          counters.PagefileUsage,
          counters.PeakPagefileUsage
          );
   }

   (void)fclose(log);

   return 0;
}
With these results:

Code: Select all

    WSS 8855552 	PWSS 9273344	PFU 5910528	PPFU 6627328
    WSS 8896512 	PWSS 9367552	PFU 5939200	PPFU 6627328
    WSS 8863744 	PWSS 9367552	PFU 5906432	PPFU 6627328
    WSS 8876032 	PWSS 9371648	PFU 5918720	PPFU 6627328
    WSS 8871936 	PWSS 9371648	PFU 5914624	PPFU 6627328
    WSS 8888320 	PWSS 9388032	PFU 5931008	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8888320 	PWSS 9388032	PFU 5931008	PPFU 6627328
    WSS 8888320 	PWSS 9388032	PFU 5931008	PPFU 6627328
    WSS 8880128 	PWSS 9388032	PFU 5922816	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8896512 	PWSS 9388032	PFU 5939200	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8896512 	PWSS 9388032	PFU 5939200	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8888320 	PWSS 9388032	PFU 5931008	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8896512 	PWSS 9388032	PFU 5939200	PPFU 6627328
    WSS 8876032 	PWSS 9388032	PFU 5918720	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8876032 	PWSS 9388032	PFU 5918720	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8908800 	PWSS 9388032	PFU 5951488	PPFU 6627328
    WSS 8884224 	PWSS 9388032	PFU 5926912	PPFU 6627328
    WSS 8904704 	PWSS 9388032	PFU 5947392	PPFU 6627328
    WSS 9101312 	PWSS 9392128	PFU 6144000	PPFU 6627328
    WSS 9232384 	PWSS 9392128	PFU 6275072	PPFU 6627328
    WSS 9162752 	PWSS 9392128	PFU 6205440	PPFU 6627328
    WSS 9166848 	PWSS 9392128	PFU 6209536	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6217728	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9154560 	PWSS 9392128	PFU 6197248	PPFU 6627328
    WSS 9162752 	PWSS 9392128	PFU 6205440	PPFU 6627328
    WSS 9166848 	PWSS 9392128	PFU 6209536	PPFU 6627328
    WSS 9150464 	PWSS 9392128	PFU 6193152	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9158656 	PWSS 9392128	PFU 6201344	PPFU 6627328
    WSS 9158656 	PWSS 9392128	PFU 6201344	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9179136 	PWSS 9392128	PFU 6221824	PPFU 6627328
    WSS 9170944 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9166848 	PWSS 9392128	PFU 6209536	PPFU 6627328
    WSS 9220096 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9170944 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9220096 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9220096 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9224192 	PWSS 9392128	PFU 6262784	PPFU 6627328
    WSS 9175040 	PWSS 9392128	PFU 6213632	PPFU 6627328
There does appear to be an upwards trend, but I'd prefer to use something like fortify, purify or valgrind to capture and track actual allocations rather than relying on the OS to report it accurately.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
carlosgc
Posts: 5
Joined: Wed Nov 14, 2007 5:26 pm

Post by carlosgc »

I am using the Windows task manager
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

I suggest you do NOT simply call

Code: Select all

device->drop();
for me, that was leaving the window still open. Instead, use:

Code: Select all

device->closeDevice(); //flag shutdown of current device
device->run(); //have to call run() after closeDevice() to finish shutting down
a screen cap is worth 0x100000 DWORDS
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

carlosgc wrote:I am using the Windows task manager
What figures are you interpreting as "memory usage"?


keless wrote:I suggest you do NOT simply call

Code: Select all

device->drop();
for me, that was leaving the window still open. Instead, use:

Code: Select all

device->closeDevice(); //flag shutdown of current device
device->run(); //have to call run() after closeDevice() to finish shutting down
How do you think his "while(device->run())" loop is exiting?
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
keless
Posts: 805
Joined: Mon Dec 15, 2003 10:37 pm
Location: Los Angeles, California, USA

Post by keless »

I'm assuming hes clicking on the window's close button-- does that call the closeDevice() method internally to irrLicht? (makes sense that it would, but I havent looked to be sure)
a screen cap is worth 0x100000 DWORDS
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

On Win32, closeDevice() doesn't do anything that simply closing the window directly doesn't already do.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
carlosgc
Posts: 5
Joined: Wed Nov 14, 2007 5:26 pm

Post by carlosgc »

What figures are you interpreting as "memory usage"?
I'm seeing the memory column of the process tab.

Other thing I forgot to tell is that it is ocurring with Windows Vista and I'm not testing the code with XP.
I'm assuming hes clicking on the window's close button
Yes, that's right.
Post Reply