Index: code/trunk/src/modules/designtools/ScreenshotManager.cc
===================================================================
--- code/trunk/src/modules/designtools/ScreenshotManager.cc	(revision 8412)
+++ code/trunk/src/modules/designtools/ScreenshotManager.cc	(revision 8413)
@@ -66,5 +66,5 @@
         Constructor. 
     */
-    ScreenshotManager::ScreenshotManager()
+    ScreenshotManager::ScreenshotManager() : finalPicturePB_(NULL), data_(NULL)
     {
         RegisterRootObject(ScreenshotManager);
@@ -78,5 +78,25 @@
     ScreenshotManager::~ScreenshotManager()
     {
-        
+        this->cleanup();
+    }
+
+    /**
+    @brief
+        Frees used memory.
+    */
+    void ScreenshotManager::cleanup(void)
+    {
+        if(this->finalPicturePB_ != NULL)
+        {
+            delete this->finalPicturePB_;
+            this->finalPicturePB_ = NULL;
+        }
+        if(this->data_ != NULL)
+        {
+            delete this->data_;
+            this->data_ = NULL;
+        }
+        if(!this->tempTexture_.isNull())
+            this->tempTexture_.freeMethod();
     }
     
@@ -101,28 +121,21 @@
         Ogre::RenderWindow* pRenderWindow = GraphicsManager::getInstance().getRenderWindow();
 
-        // If the window size has changed
-        if(this->windowWidth_ != pRenderWindow->getWidth() || this->windowHeight_ != pRenderWindow->getHeight())
-        {
-            // Update current window size
-            this->windowWidth_   = pRenderWindow->getWidth();
-            this->windowHeight_  = pRenderWindow->getHeight();
-
-            // Create temporary texture
-            this->tempTexture_ = Ogre::TextureManager::getSingleton().createManual("ScreenShotTex",
-                Resource::getDefaultResourceGroup(), Ogre::TEX_TYPE_2D, this->windowWidth_,
-                this->windowHeight_, 0, Ogre::PF_B8G8R8, Ogre::TU_RENDERTARGET);
-
-            // Get the current render target of the temporary texture
-            this->renderTarget_ = this->tempTexture_->getBuffer()->getRenderTarget();
-
-            // HardwarePixelBufferSharedPtr to the buffer of the temporary texture
-            this->buffer_ = this->tempTexture_->getBuffer();
-
-            // Create PixelBox
-            this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3];
-            this->finalPicturePB_ = Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_);
-        }
-    }
-
+        // Update current window size
+        this->windowWidth_   = pRenderWindow->getWidth();
+        this->windowHeight_  = pRenderWindow->getHeight();
+
+        // Create temporary texture
+        this->tempTexture_ = Ogre::TextureManager::getSingleton().createManual("ScreenShotTex", Resource::getDefaultResourceGroup(), Ogre::TEX_TYPE_2D, this->windowWidth_, this->windowHeight_, 0, Ogre::PF_B8G8R8, Ogre::TU_RENDERTARGET);
+
+        // Get the current render target of the temporary texture
+        this->renderTarget_ = this->tempTexture_->getBuffer()->getRenderTarget();
+
+        // HardwarePixelBufferSharedPtr to the buffer of the temporary texture
+        this->buffer_ = this->tempTexture_->getBuffer();
+
+        // Create PixelBox
+        this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3];
+        this->finalPicturePB_ = new Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_);
+    }
 
     /**
@@ -143,8 +156,7 @@
         }
         else
-        {
             COUT(1) << "There needs to be an active camera to make screenshots." << endl;
-            return;
-        }
+
+        this->cleanup();
     }
 
@@ -152,6 +164,7 @@
     @brief
         Creates a screenshot and returns it.
+        After calling this method the ScreenshotManager should be cleaned using cleanup().
     @return
-        Returns a pointer to an Ogre::Image with the screenshot.
+        Returns a pointer to an Ogre::Image with the screenshot. The memory must be freed, when the image is no longer needed.
     */
     Ogre::Image* ScreenshotManager::getScreenshot()
@@ -165,8 +178,9 @@
     @brief
         Creates a screenshot with the given camera and returns it.
+        After calling this method the ScreenshotManager should be cleaned using cleanup().
     @param camera
         A pointer to the camera the screenshot should be taken with.
     @return
-        Returns a pointer to an Ogre::Image with the screenshot.
+        Returns a pointer to an Ogre::Image with the screenshot. The memory must be freed, when the image is no longer needed.
     */
     Ogre::Image* ScreenshotManager::getScreenshot(Ogre::Camera* camera)
@@ -198,9 +212,10 @@
         if(this->gridSize_ <= 1)
         {
+            //TODO: Not working.
             // Simple case where the contents of the screen are taken directly
             // Also used when an invalid value is passed within gridSize (zero or negative grid size)
             this->renderTarget_->update(); // Render
             
-            finalImage = &finalImage->loadDynamicImage(static_cast<unsigned char*>(finalPicturePB_.data), finalPicturePB_.getWidth(), finalPicturePB_.getHeight(),Ogre::PF_B8G8R8);
+            finalImage->loadDynamicImage(static_cast<unsigned char*>(finalPicturePB_->data), finalPicturePB_->getWidth(), finalPicturePB_->getHeight(),Ogre::PF_B8G8R8);
         }
         else
@@ -240,5 +255,5 @@
                 // Copy the content from the temp buffer into the final picture PixelBox
                 // Place the tempBuffer content at the right position
-                this->buffer_->blitToMemory(this->finalPicturePB_.getSubVolume(subBox));
+                this->buffer_->blitToMemory(this->finalPicturePB_->getSubVolume(subBox));
                 
                 COUT(4) << "Created screenshot number " << nbScreenshots << " for multi grid HD screenshot." << endl;
@@ -250,5 +265,5 @@
             
             // Insert the PixelBox data into the Image Object
-            finalImage->loadDynamicImage(static_cast<unsigned char*>(this->finalPicturePB_.data), this->finalPicturePB_.getWidth(), this->finalPicturePB_.getHeight(), 1, Ogre::PF_B8G8R8, false);
+            finalImage->loadDynamicImage(static_cast<unsigned char*>(this->finalPicturePB_->data), this->finalPicturePB_->getWidth(), this->finalPicturePB_->getHeight(), 1, Ogre::PF_B8G8R8, false);
         }
         
@@ -275,7 +290,4 @@
 
         this->gridSize_ = size;
-        // New PixelBox for the changed size.
-        this->data_ = new uint8_t[(this->windowWidth_ * this->gridSize_) * (this->windowHeight_ * this->gridSize_) * 3];
-        this->finalPicturePB_ = Ogre::PixelBox(this->windowWidth_ * this->gridSize_, this->windowHeight_ * this->gridSize_, 1, Ogre::PF_B8G8R8, this->data_);
     }
 
Index: code/trunk/src/modules/designtools/ScreenshotManager.h
===================================================================
--- code/trunk/src/modules/designtools/ScreenshotManager.h	(revision 8412)
+++ code/trunk/src/modules/designtools/ScreenshotManager.h	(revision 8413)
@@ -53,5 +53,4 @@
         Class encapsulates screenshot functionality and provides a method for making multi grid (i.e. HD) screenshots.
         
-        
     @author
         This code comes from http://www.ogre3d.org/tikiwiki/High+resolution+screenshots which is Public Domain.
@@ -88,4 +87,6 @@
             inline unsigned int getGridSize(void)
                 { return this->gridSize_; }
+
+            void cleanup(void); // Frees used memory.
             
         protected:
@@ -103,5 +104,5 @@
             Ogre::HardwarePixelBufferSharedPtr buffer_; //!< Buffer for the temporary texture.
             
-            Ogre::PixelBox finalPicturePB_; //!< PixelBox for large screenshots, contains the screenshot for gridSize_ > 1.
+            Ogre::PixelBox* finalPicturePB_; //!< PixelBox for large screenshots, contains the screenshot for gridSize_ > 1.
             uint8_t* data_; //!< Data pointer for the PixelBox.
 
Index: code/trunk/src/modules/designtools/SkyboxGenerator.cc
===================================================================
--- code/trunk/src/modules/designtools/SkyboxGenerator.cc	(revision 8412)
+++ code/trunk/src/modules/designtools/SkyboxGenerator.cc	(revision 8413)
@@ -315,4 +315,5 @@
         image->save(PathConfig::getInstance().getLogPathString()+name);
         delete image;
+        ScreenshotManager::getInstance().cleanup(); // Free memory in ScreenshotManager.
     }
 }
