Skip to content

Commit b7dfb46

Browse files
committed
cleaned up presentation
1 parent 627a56a commit b7dfb46

File tree

2 files changed

+33
-19
lines changed

2 files changed

+33
-19
lines changed

Sources/source/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ In This Collection
2626

2727
These materials copyright Christopher H. Barker
2828

29-
Licenced under the Creative Commons Attribution-ShareAlike 4.0 International Public License.
29+
Licensed under the Creative Commons Attribution-ShareAlike 4.0 International Public License.
3030

3131
https://creativecommons.org/licenses/by-sa/4.0/legalcode
3232

Sources/source/weak_references.rst

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,16 @@ The Limits of Reference Counting
188188
Circular references
189189

190190
If 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!
240245
Examples
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

259269
Weak 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+
=========
279291
Exercise
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

Comments
 (0)