=== modified file 'source.list'
--- source.list	2008-04-07 17:19:50 +0000
+++ source.list	2008-04-13 15:37:37 +0000
@@ -167,6 +167,7 @@
 map_type.h
 core/math_func.hpp
 md5.h
+mem_init.h
 minilzo.h
 mixer.h
 music.h

=== modified file 'src/window.cpp'
--- src/window.cpp	2008-04-13 13:49:43 +0000
+++ src/window.cpp	2008-04-13 15:52:55 +0000
@@ -25,14 +25,12 @@
 static Point _drag_delta; //< delta between mouse cursor and upper left corner of dragged window
 static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event
 
-static Window _windows[MAX_NUMBER_OF_WINDOWS];
-
 /**
  * List of windows opened at the screen.
  * Uppermost window is at  _z_windows[_last_z_window - 1],
  * bottom window is at _z_windows[0]
  */
-Window *_z_windows[lengthof(_windows)];
+Window *_z_windows[MAX_NUMBER_OF_WINDOWS];
 Window **_last_z_window; ///< always points to the next free space in the z-array
 
 Point _cursorpos_drag_start;
@@ -446,6 +444,8 @@
 	if (wz == NULL) return;
 	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
 	_last_z_window--;
+
+	delete w;
 }
 
 /**
@@ -668,28 +668,6 @@
 	}
 }
 
-static Window *FindFreeWindow()
-{
-	Window *w;
-
-	for (w = _windows; w < endof(_windows); w++) {
-		Window* const *wz;
-		bool window_in_use = false;
-
-		FOR_ALL_WINDOWS(wz) {
-			if (*wz == w) {
-				window_in_use = true;
-				break;
-			}
-		}
-
-		if (!window_in_use) return w;
-	}
-
-	assert(_last_z_window == endof(_z_windows));
-	return NULL;
-}
-
 /** Open a new window.
  * This function is called from AllocateWindow() or AllocateWindowDesc()
  * See descriptions for those functions for usage
@@ -710,17 +688,18 @@
 static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height, int def_width, int def_height,
 				WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
 {
-	Window *w = FindFreeWindow();
+	Window *w;
 
 	/* We have run out of windows, close one and use that as the place for our new one */
-	if (w == NULL) {
+	if (_last_z_window == endof(_z_windows)) {
 		w = FindDeletableWindow();
 		if (w == NULL) w = ForceFindDeletableWindow();
 		DeleteWindow(w);
 	}
 
+	w = new Window;
+
 	/* Set up window properties */
-	memset(w, 0, sizeof(*w));
 	w->window_class = cls;
 	w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
 	w->caption_color = 0xFF;
@@ -1071,7 +1050,6 @@
 {
 	IConsoleClose();
 
-	memset(&_windows, 0, sizeof(_windows));
 	_last_z_window = _z_windows;
 	InitViewports();
 	_no_scroll = 0;

=== modified file 'src/window_gui.h'
--- src/window_gui.h	2008-04-13 13:50:58 +0000
+++ src/window_gui.h	2008-04-13 15:34:45 +0000
@@ -10,6 +10,7 @@
 #include "viewport_type.h"
 #include "player_type.h"
 #include "strings_type.h"
+#include "mem_init.h"
 
 /**
  * The maximum number of windows that can be opened.
@@ -289,7 +290,7 @@
 /**
  * Data structure for an opened window
  */
-class Window
+class Window: public MemInitialize
 {
 public:
 	Window();

