开发者

Is there an expression which dictates which form of delete is used (implicite versus complete)?

开发者 https://www.devze.com 2023-03-11 08:14 出处:网络
Let\'s say I have class A(<class ...>): pass. Should I be explicitly calling del for a deep delete? Let me be more specific: What happens just before a fork merge with a current thread? When a t

Let's say I have class A(<class ...>): pass. Should I be explicitly calling del for a deep delete? Let me be more specific: What happens just before a fork merge with a current thread? When a thread is being interwoven开发者_如何学JAVA with another, does it thrash or use a pointer?

EDIT

Aha! http://docs.python.org/library/gc.html


The del keyword doesn't actually explicitly remove an object. It decrements the reference count, and then the garbage collector cleans up the memory if nothing else is using it. It's useful when you have a block of code that will be running for a long time, and a variable that's eating up a lot of memory that you don't need anymore.

Once you exit the scope of a function, all variables will have their reference count decremented (and cleaned up if appropriate). There is nothing deep or special about an explicit call to del.

Oh I should also mention that the del command removes the variable name from the local scope. So from your point of view the variable is gone. However if other things are referencing the object being pointed to, the memory itself will not be cleaned up (yet).

EDIT

Forks don't merge. You can wait on a fork to exit, but that's it. And when you join another thread, they aren't being merged there either. They have different stacks (but the same heap). When a thread ends, all variables within that thread's scope have their reference count decremented (and cleaned up if appropriate). I don't understand you question about thrashing and pointers -- I have no idea what thrashing means, and python doesn't have pointers.

0

精彩评论

暂无评论...
验证码 换一张
取 消