472,353 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Releasing weakrefed objects immediately?

Hi all,

I've been toying with an idea of dependency-based coding, in which you
construct a graph of code dependencies. Say, you have independent
variables 'a' and 'b', and a function f(x,y). Now, you can define that a,b
are dependencies for f(a,b). Whenever a or b are changed, f(a,b) is marked
dirty, and if its value is requested, all the dirty dependencies are
recomputed to evaluate the value of f(a,b). Basically the same idea as in

I also want to have listener objects, so that I could make a GUI text box
depend on f(a,b) so that its value is updated whenever a or b are
modified. So far so good, and all of this I have already implemented. My
problem, however, is that I want to be able to destroy the listener
objects at will, for example when a window is closed. Unfortunately, even
though the only real reference to an object is destroyed, the weak
references seem to keep the listener alive (or the garbage collector won't
kick in for some other reason, even though explicitly called).

Here is the code snippet for my test case:

def testlistener(self):
self.input1 = Dep(value=3,id="input1")
self.input2 = Dep(value=4,id="input2")
self.output1 = Dep((self.input1,self.input2),lambda x,y: x*y,
self.listenerResult = 0
def listenerFunc(self,x):
self.listenerResult = x
self.listener1 = Dep((self.output1,),
lambda x: listenerFunc(self,x),
self.input1.value = 5
#self.listener1._code = lambda x: x
del self.listener1
self.input1.value = 4

The self.listenerResults always is 16 in the final asserEqual, despite
that I have deleted the listener. If I "neuter" the listener by
uncommenting the commented line, I get the right result. So, how could I
make sure that the listener is no longer called when the only strong ref
is removed?

The actual depcode class with the complete testcase and another example
using scipy and matplotlib is available at
http://www.mairas.net/tmp/depcode/ . Note that it is very much code in
progress at the moment.

Thanks for any hints,

Matti Airas

Oct 20 '06 #1
0 954

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

Similar topics

by: lylefair | last post by:
Can you post code, or a reference to a md? or ad? file on a website, where object variables are not released when they go out of scope and cause a...
by: Chris | last post by:
Hi, to create an array of 2 objects (e.g. of type '__gc class Airplane') I need to do : Airplane * arrAirplanes __gc = new Airplane* __gc;...
by: One Handed Man [ OHM# ] | last post by:
Scenario. PDA connecting to a web service method using a reference on XP professional ( IIS ). XP limited to 10 sessions. How can the session...
by: M.Ob | last post by:
Hello... I am having issues with my asp.net apps not releasing memory. The memory usage for the process w3p.exe continues to grow to it's...
by: Pete Smith | last post by:
I have written print application which prints multiple pages by calling PrintPage event multiple times. I am closing all the databases related...
by: B.N.Prabhu | last post by:
In my web application(C#) . I am adding one excel sheet and then save and closing that excel file. In the finally bloack i gave ...
by: iker.arizmendi | last post by:
Is there any way to get Python to release memory back to the C allocator? I'm currently running a script that goes through the following steps: ...
by: 062699 | last post by:
Hi All, Thank you in advance. I am having trouble releasing resources when I open a child form. Please see the code below. Form f; private void...
by: amollokhande1 | last post by:
Hi All, We have ASP.Net based content management web application. We are performing lots of XML based operations like setting the innerxml,...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.