Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
ZODB
Commits
057ab400
Commit
057ab400
authored
Mar 07, 2005
by
Tim Peters
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more words about __del__ methods.
parent
2d90abbd
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
2 deletions
+35
-2
branches/3.3/doc/guide/prog-zodb.tex
branches/3.3/doc/guide/prog-zodb.tex
+35
-2
branches/3.3/doc/zodb.pdf
branches/3.3/doc/zodb.pdf
+0
-0
No files found.
branches/3.3/doc/guide/prog-zodb.tex
View file @
057ab400
...
...
@@ -300,11 +300,11 @@ methods. (Older versions didn't support this at all.) If you write
such a
\method
{__
setattr
__}
or
\method
{__
delattr
__}
method, its code
has to set the dirty bit manually.
\item
A persistent class should not have a
n
\method
{__
del
__}
method.
\item
A persistent class should not have a
\method
{__
del
__}
method.
The database moves objects freely between memory and storage. If an
object has not been used in a while, it may be released and its
contents loaded from storage the next time it is used. Since the
Python interpreter is unaware of persistence, it would call
the
Python interpreter is unaware of persistence, it would call
\method
{__
del
__}
each time the object was freed.
\end{itemize}
...
...
@@ -407,6 +407,39 @@ the name of the attribute as an argument. If the call returns True,
\class
{
Persistent
}
handled the attribute; if not, the user code can
run.
\subsubsection
{
\method
{__
del
__}
methods
}
A
\method
{__
del
__}
method is invoked just before the memory occupied by an
unreferenced Python object is freed. Because ZODB may materialize, and
dematerialize, a given persistent object in memory any number of times,
there isn't a meaningful relationship between when a persistent object's
\method
{__
del
__}
method gets invoked and any natural aspect of a
persistent object's life cycle. For example, it is emphatically not the
case that a persistent object's
\method
{__
del
__}
method gets invoked only
when the object is no longer referenced by other objects in the database.
\method
{__
del
__}
is only concerned with reachability from objects in
memory.
Worse, a
\method
{__
del
__}
method can interfere with the persistence
machinery's goals. For example, some number of persistent objects reside
in a
\class
{
Connection
}
's memory cache. At various times, to reduce memory
burden, objects that haven't been referenced recently are removed from the
cache. If a persistent object with a
\method
{__
del
___}
method is so
removed, and the cache was holding the last memory reference to the object,
the object's
\method
{__
del
__}
method will be invoked. If the
\method
{__
del
__}
method then references any attribute of the object, ZODB
needs to load the object from the database again, in order to satisfy the
attribute reference. This puts the object back into the cache again: such
an object is effectively immortal, occupying space in the memory cache
forever, as every attempt to remove it from cache puts it back into the
cache. In ZODB versions prior to 3.2.2, this could even cause the cache
reduction code to fall into an infinite loop. The infinite loop no longer
occurs, but such objects continue to live in the memory cache forever.
Because
\method
{__
del
__}
methods don't make good sense for persistent
objects, and can create problems, persistent classes should not define
\method
{__
del
__}
methods.
\subsection
{
Writing Persistent Classes
}
Now that we've looked at the basics of programming using the ZODB,
...
...
branches/3.3/doc/zodb.pdf
View file @
057ab400
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment