Index: /CKEditor/trunk/CHANGES.html
===================================================================
--- /CKEditor/trunk/CHANGES.html	(revision 5230)
+++ /CKEditor/trunk/CHANGES.html	(revision 5231)
@@ -61,4 +61,5 @@
 		<li><a href="http://dev.fckeditor.net/ticket/3570">#3570</a> : SCAYT marker should not appear in elementspath bar.</li>
 		<li><a href="http://dev.fckeditor.net/ticket/4553">#4553</a> : Dirty check result incorrect when editor document is empty.</li>
+		<li><a href="http://dev.fckeditor.net/ticket/4555">#4555</a> : Non-released memory when editor is created and destroyed.</li>
 	</ul>
 	<h3>
Index: /CKEditor/trunk/_source/core/dom/domobject.js
===================================================================
--- /CKEditor/trunk/_source/core/dom/domobject.js	(revision 5230)
+++ /CKEditor/trunk/_source/core/dom/domobject.js	(revision 5231)
@@ -116,4 +116,24 @@
 				}
 			}
+		},
+
+		/**
+		 * Removes any listener set on this object.
+		 * To avoid memory leaks we must assure that there are no
+		 * references left after the object is no longer needed.
+		 */
+		removeAllListeners : function()
+		{
+			var nativeListeners = this.getCustomData( '_cke_nativeListeners' );
+			for ( eventName in nativeListeners)
+			{
+				var listener = nativeListeners[ eventName ];
+				if ( this.$.removeEventListener )
+					this.$.removeEventListener( eventName, listener, false );
+				else if ( this.$.detachEvent )
+					this.$.detachEvent( 'on' + eventName, listener );
+
+				delete nativeListeners[ eventName ];
+			}
 		}
 	};
@@ -198,4 +218,20 @@
 
 	/**
+	 * Removes any data stored on this object.
+	 * To avoid memory leaks we must assure that there are no
+	 * references left after the object is no longer needed.
+	 * @name CKEDITOR.dom.domObject.prototype.clearCustomData
+	 * @function
+	 */
+	domObjectProto.clearCustomData = function()
+	{
+		// Clear all event listeners
+		this.removeAllListeners();
+
+		var expandoNumber = this.$._cke_expando;
+		expandoNumber && delete customData[ expandoNumber ];
+	};
+
+	/**
 	 * @name CKEDITOR.dom.domObject.prototype.getCustomData
 	 */
Index: /CKEditor/trunk/_source/core/editor.js
===================================================================
--- /CKEditor/trunk/_source/core/editor.js	(revision 5230)
+++ /CKEditor/trunk/_source/core/editor.js	(revision 5231)
@@ -469,5 +469,45 @@
 				this.updateElement();
 
+			if ( this.mode )
+			{
+				// ->		currentMode.unload( holderElement );
+				this._.modes[ this.mode ].unload( this.getThemeSpace( 'contents' ) );
+			}
+
 			this.theme.destroy( this );
+
+			var toolbars,
+				index = 0,
+				j,
+				items,
+				instance;
+
+			if ( this.toolbox )
+			{
+				toolbars = this.toolbox.toolbars;
+				for ( ; index < toolbars.length ; index++ )
+				{
+					items = toolbars[ index ].items;
+					for ( j = 0 ; j < items.length ; j++ )
+					{
+						instance = items[ j ];
+						if ( instance.clickFn ) CKEDITOR.tools.removeFunction( instance.clickFn );
+						if ( instance.keyDownFn ) CKEDITOR.tools.removeFunction( instance.keyDownFn );
+
+						if ( instance.index ) CKEDITOR.ui.button._.instances[ instance.index ] = null;
+					}
+				}
+			}
+
+			if ( this.contextMenu )
+				CKEDITOR.tools.removeFunction( this.contextMenu._.functionId );
+
+			if ( this._.filebrowserFn )
+				CKEDITOR.tools.removeFunction( this._.filebrowserFn );
+
+			items = editor.config.elementsPath_filters;
+			for ( index= 0 ; index < items.length ; index++ )
+				items[ index ] = null;
+
 			this.fire( 'destroy' );
 			CKEDITOR.remove( this );
Index: /CKEditor/trunk/_source/core/imagecacher.js
===================================================================
--- /CKEditor/trunk/_source/core/imagecacher.js	(revision 5230)
+++ /CKEditor/trunk/_source/core/imagecacher.js	(revision 5231)
@@ -12,4 +12,5 @@
 		var doCallback = function()
 			{
+				img.removeAllListeners();
 				loaded[ image ] = 1;
 				callback();
Index: /CKEditor/trunk/_source/plugins/button/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/button/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/button/plugin.js	(revision 5231)
@@ -70,7 +70,11 @@
 	render : function( editor, output )
 	{
-		var env = CKEDITOR.env;
-
-		var id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber();
+		var env = CKEDITOR.env,
+			id = this._.id = 'cke_' + CKEDITOR.tools.getNextNumber(),
+			classes = '',
+			command = this.command, // Get the command name.
+			clickFn,
+			index;
+
 		this._.editor = editor;
 
@@ -91,12 +95,7 @@
 		};
 
-		var clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );
-
-		var index = CKEDITOR.ui.button._.instances.push( instance ) - 1;
-
-		var classes = '';
-
-		// Get the command name.
-		var command = this.command;
+		instance.clickFn = clickFn = CKEDITOR.tools.addFunction( instance.execute, instance );
+
+		instance.index = index = CKEDITOR.ui.button._.instances.push( instance ) - 1;
 
 		if ( this.modes )
Index: /CKEditor/trunk/_source/plugins/filebrowser/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/filebrowser/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/filebrowser/plugin.js	(revision 5231)
@@ -379,20 +379,20 @@
 		{
 			editor._.filebrowserFn = CKEDITOR.tools.addFunction( setUrl, editor );
-
-			CKEDITOR.on( 'dialogDefinition', function( evt )
-			{
-				var definition = evt.data.definition,
-					element;
-				// Associate filebrowser to elements with 'filebrowser' attribute.
-				for ( var i in definition.contents )
-				{
-					element = definition.contents[ i ] ;
-					attachFileBrowser( evt.editor, evt.data.name, definition, element.elements );
-					if ( element.hidden && element.filebrowser )
-					{
-						element.hidden = !isConfigured( definition, element[ 'id' ], element.filebrowser );
-					}
-				}
-			} );
+		}
+	} );
+
+	CKEDITOR.on( 'dialogDefinition', function( evt )
+	{
+		var definition = evt.data.definition,
+			element;
+		// Associate filebrowser to elements with 'filebrowser' attribute.
+		for ( var i in definition.contents )
+		{
+			element = definition.contents[ i ] ;
+			attachFileBrowser( evt.editor, evt.data.name, definition, element.elements );
+			if ( element.hidden && element.filebrowser )
+			{
+				element.hidden = !isConfigured( definition, element[ 'id' ], element.filebrowser );
+			}
 		}
 	} );
Index: /CKEditor/trunk/_source/plugins/resize/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/resize/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/resize/plugin.js	(revision 5231)
@@ -55,4 +55,6 @@
 					}
 				} );
+
+			editor.on( 'destroy', function() { CKEDITOR.tools.removeFunction( mouseDownFn ) } );
 
 			editor.on( 'themeSpace', function( event )
Index: /CKEditor/trunk/_source/plugins/richcombo/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/richcombo/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/richcombo/plugin.js	(revision 5231)
@@ -131,5 +131,5 @@
 					element.focus();
 				},
-				execute : clickFn
+				clickFn : clickFn
 			};
 
@@ -162,4 +162,7 @@
 				});
 
+			// For clean up
+			instance.keyDownFn = keyDownFn;
+
 			output.push(
 				'<span class="cke_rcombo">',
Index: /CKEditor/trunk/_source/plugins/showborders/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/showborders/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/showborders/plugin.js	(revision 5231)
@@ -130,34 +130,31 @@
 				} );
 			}
+		}
+	});
 
-			// Table dialog must be aware of it.
-			CKEDITOR.on( 'dialogDefinition', function( ev )
-				{
-					if ( ev.editor != editor )
-						return;
+	// Table dialog must be aware of it.
+	CKEDITOR.on( 'dialogDefinition', function( ev )
+	{
+		var dialogName = ev.data.name;
 
-					var dialogName = ev.data.name;
+		if ( dialogName == 'table' || dialogName == 'tableProperties' )
+		{
+			var dialogDefinition = ev.data.definition,
+				infoTab = dialogDefinition.getContents( 'info' ),
+				borderField = infoTab.get( 'txtBorder' ),
+				originalCommit = borderField.commit;
 
-					if ( dialogName == 'table' || dialogName == 'tableProperties' )
+			borderField.commit = CKEDITOR.tools.override( originalCommit, function( org )
+			{
+				return function( data, selectedTable )
 					{
-						var dialogDefinition = ev.data.definition,
-							infoTab = dialogDefinition.getContents( 'info' ),
-							borderField = infoTab.get( 'txtBorder' ),
-							originalCommit = borderField.commit;
+						org.apply( this, arguments );
+						var value = parseInt( this.getValue(), 10 );
+						selectedTable[ ( !value || value <= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName );
+					};
+			} );
+		}
+	});
 
-						borderField.commit = CKEDITOR.tools.override( originalCommit, function( org )
-						{
-							return function( data, selectedTable )
-								{
-									org.apply( this, arguments );
-									var value = parseInt( this.getValue(), 10 );
-									selectedTable[ ( !value || value <= 0 ) ? 'addClass' : 'removeClass' ]( showBorderClassName );
-								};
-						} );
-					}
-				});
-		}
-
-	});
 } )();
 
Index: /CKEditor/trunk/_source/plugins/sourcearea/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/sourcearea/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/sourcearea/plugin.js	(revision 5231)
@@ -139,4 +139,5 @@
 						unload : function( holderElement )
 						{
+							textarea.clearCustomData();
 							editor.textarea = textarea = null;
 
Index: /CKEditor/trunk/_source/plugins/toolbar/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/toolbar/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/toolbar/plugin.js	(revision 5231)
@@ -283,4 +283,8 @@
 								{
 									editor.execCommand( 'toolbarCollapse' );
+								} );
+
+							editor.on( 'destroy', function () {
+									CKEDITOR.tools.removeFunction( collapserFn );
 								} );
 
Index: /CKEditor/trunk/_source/plugins/wysiwygarea/plugin.js
===================================================================
--- /CKEditor/trunk/_source/plugins/wysiwygarea/plugin.js	(revision 5230)
+++ /CKEditor/trunk/_source/plugins/wysiwygarea/plugin.js	(revision 5231)
@@ -692,4 +692,10 @@
 							unload : function( holderElement )
 							{
+								editor.document.getDocumentElement().clearCustomData();
+								editor.document.getBody().clearCustomData();
+
+								editor.window.clearCustomData();
+								editor.document.clearCustomData();
+
 								editor.window = editor.document = iframe = mainElement = isPendingFocus = null;
 
@@ -760,4 +766,8 @@
 						} );
 				} );
+				editor.on( 'destroy', function()
+				{
+					ieFocusGrabber.clearCustomData();
+				} );
 			}
 		}
Index: /CKEditor/trunk/_source/themes/default/theme.js
===================================================================
--- /CKEditor/trunk/_source/themes/default/theme.js	(revision 5230)
+++ /CKEditor/trunk/_source/themes/default/theme.js	(revision 5231)
@@ -230,4 +230,6 @@
 		{
 			var container = editor.container;
+			container.clearCustomData();
+			editor.element.clearCustomData();
 
 			/*
@@ -257,8 +259,7 @@
 
 			if ( editor.elementMode == CKEDITOR.ELEMENT_MODE_REPLACE )
-			{
 				editor.element.show();
-				delete editor.element;
-			}
+
+			delete editor.element;
 		}
 	};
