@@ -188,11 +188,16 @@ The Limits of Reference Counting
188188 Circular references
189189
190190If a python object references another object that references the first
191- object: You have a circular reference:
191+ object:
192192
193- . ...
193+ You have a circular reference ...
194194
195- .. nextslide ::
195+ ===================
196+ Circular References
197+ ===================
198+
199+ Circular Reference Example
200+ --------------------------
196201
197202.. code-block :: ipython
198203
@@ -240,21 +245,26 @@ But it can be slow, and doesn't always work!
240245Examples
241246----------
242247
248+ A really simple example:
249+
250+ :download: `simple_circular.py <../code/weak_references/simple_circular.py >`
251+
243252
244- Example in iPython notebook: :
253+ More real example in iPython notebook:
245254
246- code/CircularReferenceExample.ipynb
255+ :download: ` CircularReferenceExample.ipynb < ../ code/weak_references/ CircularReferenceExample.ipynb>`
247256
248- You can also run: :
257+ If you don't have the notebook running :
249258
250- circular.py
259+ :download: ` circular.py < ../code/weak_references/ circular.py>`
251260
252- And::
261+ And :download: `memcount.py <../code/weak_references/memcount.py >` is a test
262+ file that show memory growth if circular references are not cleaned up.
253263
254- memcount.py
255264
256- ``mem_check.py `` is code that reports process memory use
257- -- only *nix for now -- sorry!
265+ ( :download: `mem_check.py <../code/weak_references/mem_check.py >` )
266+ is code that reports process memory use.
267+
258268
259269Weak References
260270-----------------
@@ -273,21 +283,25 @@ Three ways to use them:
273283
274284* ``Proxy `` objects
275285 - act much like regular references -- client code doesn't know the difference
286+
276287* ``WeakRef `` objects
277288 - When you want to control what happens when the referenced object is gone.
278289
290+ =========
279291Exercise
280- ---------
292+ =========
293+
294+ .. rst-class :: left
281295
282- Build a "weak cache":
296+ Build a "weak cache":
283297
284- For large objects that are expensive to create:
298+ For large objects that are expensive to create:
285299
286- * Use a WeakValueDictionay to hold references to (probably large) objects.
300+ * Use a WeakValueDictionay to hold references to (probably large) objects.
287301
288- * When the client requests an object that doesn't exist -- one is created, returned, and cached (weakly).
302+ * When the client requests an object that doesn't exist -- one is created, returned, and cached (weakly).
289303
290- * If the object is in the cache, it is returned.
304+ * If the object is in the cache, it is returned.
291305
292- * when not other references exist to the object, it is NOT retained by the cache.
306+ * when no other references exist to the object, it is NOT retained by the cache.
293307
0 commit comments