Index: /trunk/source/examples/cocoa/nib-loading/HOWTO.html
===================================================================
--- /trunk/source/examples/cocoa/nib-loading/HOWTO.html	(revision 8499)
+++ /trunk/source/examples/cocoa/nib-loading/HOWTO.html	(revision 8500)
@@ -282,4 +282,58 @@
         needed.</p>
 
+      <p>The nib-loading function can simply parameterize the file to
+      be loaded, and then perform the sequence of steps covered in the
+      previous section. If we just literally do that, the result will
+      look something like this:</p>
+
+      <pre>
+(defun load-nibfile (nib-path)
+  (let* ((app-class-name (%make-nsstring "NSApplication"))
+         (app-class (#_NSClassFromString class-name))
+         (app (#/sharedApplication appclass))
+         (app-zone (#/zone app))
+         (nib-name (%make-nsstring (namestring nib-path)))
+         (dict (#/dictionaryWithObject:forKey: 
+                (@class ns-mutable-dictionary) app #@"NSNibOwner")))
+    (#/loadNibFile:externalNameTable:withZone: (@class ns-bundle)
+                                               nib-name
+                                               dict
+                                               app-zone)))
+      </pre>
+
+      <p>The trouble with this function is that it leaks two strings
+      and a dictionary every time we call it. We need to release the
+      variables <code>app-class-name</code>, <code>nib-name</code>,
+      and <code>dict</code> before returning. So how about this
+      version instead?</p>
+
+      <pre>
+(defun load-nibfile (nib-path)
+  (let* ((app-class-name (%make-nsstring "NSApplication"))
+         (app-class (#_NSClassFromString class-name))
+         (app (#/sharedApplication appclass))
+         (app-zone (#/zone app))
+         (nib-name (%make-nsstring (namestring nib-path)))
+         (dict (#/dictionaryWithObject:forKey: 
+                (@class ns-mutable-dictionary) app #@"NSNibOwner"))
+         (result (#/loadNibFile:externalNameTable:withZone: (@class ns-bundle)
+                                                            nib-name
+                                                            dict
+                                                            app-zone)))
+    (#/release app-class-name)
+    (#/release nib-name)
+    (#/release dict)
+    result))
+      </pre>
+
+      <p>This version solves the leaking problem by binding the result
+      of the load call to <code>result</code>, then releasing the
+      variables in question before returning the result of the
+      load.</p>
+
+      <p>There's just one more problem: what if we want to use the
+      dictionary to collect the nibfile's toplevel objects, so that we
+      can get access to them from our code? We'll need another version
+      of our function.</p>
 
       <div class="section-head">
@@ -293,5 +347,5 @@
       the <code>"NSNibTopLevelObjects"</code> key with the dictionary
       object that you pass
-      to <code>loadNibFile:externalNameTable:withZone:</code>7mdash;to
+      to <code>loadNibFile:externalNameTable:withZone:</code>&mdash;to
       obtain a collection of toplevel objects that you release when
       the nibfile is no longer needed.</p>
@@ -299,9 +353,9 @@
       <p>In document-based Cocoa applications, the main nibfile is
       usually owned by the application object, and is never unloaded
-      while the appliation runs. Auxliliary nibfiles are normally
+      while the application runs. Auxliliary nibfiles are normally
       owned by controller objects, usually instances of
       <code>NSWindowController</code> subclasses. When you
       use <code>NSWindowController</code> objects to load nibfiles,
-      they take responsbility for loading and unloading nibfile
+      they take responsibility for loading and unloading nibfile
       objects.</p>
 
@@ -312,5 +366,5 @@
       management yourself. On the one hand, loading nibfiles by hand
       is not likely to be the source of major application problems. On
-      the other hand, if you experiement with nib-loading for a long
+      the other hand, if you experiment with nib-loading for a long
       time in an interactive session, it's possible that you'll end up
       with numerous discarded objects cluttering memory, along with
Index: /trunk/source/examples/cocoa/nib-loading/nib-loading.lisp
===================================================================
--- /trunk/source/examples/cocoa/nib-loading/nib-loading.lisp	(revision 8499)
+++ /trunk/source/examples/cocoa/nib-loading/nib-loading.lisp	(revision 8500)
@@ -13,23 +13,19 @@
 
 (defun load-nibfile (nib-path)
-  (let* ((appclass (#_NSClassFromString (%make-nsstring "NSApplication")))
+  (let* ((app-class-name (%make-nsstring "NSApplication"))
+         (app-class (#_NSClassFromString class-name))
          (app (#/sharedApplication appclass))
          (app-zone (#/zone app))
          (nib-name (%make-nsstring (namestring nib-path)))
-         (toplevel-objects-array (#/arrayWithCapacity: (@class ns-mutable-array) 8))
-         (context (#/dictionaryWithObjectsAndKeys: (@class ns-mutable-dictionary)
-                                                   app #@"NSNibOwner" 
-                                                   toplevel-objects-array #@"NSNibTopLevelObjects"))
-         (load-succeeded-p (#/loadNibFile:externalNameTable:withZone: (@class ns-bundle)
-                                                                      nib-name context app-zone)))
-    (values load-succeeded-p context)))
-
-(setf  *my-app*
-       (let* ((class-name (%make-nsstring "NSApplication"))
-              (appclass (#_NSClassFromString class-name)))
-         (#/release class-name)
-         (#/sharedApplication appclass)))
-
-
+         (dict (#/dictionaryWithObject:forKey: 
+                (@class ns-mutable-dictionary) app #@"NSNibOwner"))
+         (result (#/loadNibFile:externalNameTable:withZone: (@class ns-bundle)
+                                                            nib-name
+                                                            dict
+                                                            app-zone)))
+    (#/release app-class-name)
+    (#/release nib-name)
+    (#/release dict)
+    result))
 #|
 (ccl::load-nibfile "/usr/local/openmcl/trunk/source/examples/cocoa/nib-loading/hello.nib")
