473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Do we need to delete "ImageDraw.Draw" after using it?

Hello all:

I am looking the sample code posted on PIL website
http://www.pythonware.com/library/pi.../imagedraw.htm

################################################
<<Draw a Grey Cross Over an Image>>

import Image, ImageDraw

im = Image.open("lena.pgm")

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw # ===>>>Why we should delete this object draw?

# write to stdout
im.save(sys.stdout, "PNG")
#################################################

Is there any general rule that we must delete the object after using
it?
Thank you
-Daniel

Sep 20 '06 #1
3 6417
"Daniel Mark" <da***********@gmail.comwrote:
Is there any general rule that we must delete the object after using
it?
In general: if the object is not destroyed when it goes out of scope (but
later) and uses precious resources [1], or if a special clean up is
required, you should delete it explicitly.
[1] like file handles

--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
Sep 20 '06 #2
Daniel Mark wrote:
Hello all:

I am looking the sample code posted on PIL website
http://www.pythonware.com/library/pi.../imagedraw.htm

################################################
<<Draw a Grey Cross Over an Image>>

import Image, ImageDraw

im = Image.open("lena.pgm")

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw # ===>>>Why we should delete this object draw?

# write to stdout
im.save(sys.stdout, "PNG")
#################################################

Is there any general rule that we must delete the object after using
it?
Just consider it good hygiene.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 20 '06 #3
Steve Holden wrote:
>Is there any general rule that we must delete the object after using
it?
Just consider it good hygiene.
in this specific case, it may not be obvious for the casual reader that
the global "draw" variable will contain an indirect reference to the
original image object, so even if you throw away (or replace) the "im"
variable with something else, the original image will still be present
in memory.

if you put the same code inside a function, you can safely leave the
garbage handling to Python.

</F>

Sep 21 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Alex Vinokur | last post by:
http://www.parashift.com/c++-faq-lite/virtual-functions.html#faq-20.6 Faq-20.6 contains function userCode(Shape&) : void userCode(Shape& s) { Shape* s2 = s.clone(); Shape* s3 = s.create();...
2
by: tvmaly | last post by:
I have been trying to add a watermark to a jpeg using PIL, but the watermark has a black box around it. I looked at http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/362879 and ...
7
by: qvx | last post by:
Hi all, I have a performance problem in my app. It is a poor man's version of OCR app. I started this app as a prototype before implementing it in C++. But now, after I have a working copy in...
3
by: Tobias Froehlich | last post by:
Hello, I'd like to create a drawing field on a form in which I can draw (using the Pen class I guess). I've found tutorials on how to use the GDI+ but I still haven't found out how to actually...
2
by: VB Programmer | last post by:
I created a VB.NET user control which I now want to use in my ASP.NET webform. The uc shows up fine in my toolbar, but when I click on it it goes to the bottom of the form, rather than letting me...
18
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12,...
8
by: gw7rib | last post by:
I've been bitten twice now by the same bug, and so I thought I would draw it to people's attention to try to save others the problems I've had. The bug arises when you copy code from a destructor...
4
by: jk2l | last post by:
Error 10 error LNK2019: unresolved external symbol __imp__glBindTexture@8 referenced in function "public: void __thiscall GLTexture::Use(void)" (?Use@GLTexture@@QAEXXZ) GLTexture.obj Error 11 error...
2
by: ValValVal | last post by:
Hi all. I am creating a chess game and now I need draw pieces on board. Creating every shape using GeneralPath and curves that are part of Graphics2D is difficult, especially when I draw a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.