Rule Overwriting, Rule Removal and Garbage Collection

2 views
Skip to first unread message

dtyrell

unread,
Mar 23, 2009, 3:47:04 AM3/23/09
to Smartypants IOC
Greetings,

3 new questions today:

1) Do duplicate rules on the same Injector get "overwritten"?

injector.newRule().whenAskedFor( SomeClass ).useInstance( someObj );
injector.newRule().whenAskedFor( SomeClass ).useInstance
( someOtherObj );

2) Assuming there are no other references to someObj, will it be free
for Garbage Collection at this point?

3) How might I free someOtherObj for GC later?

Josh McDonald

unread,
Mar 23, 2009, 4:13:56 AM3/23/09
to smartyp...@googlegroups.com
For 1 & 2, the new rule should overwrite the old, and someObj should become available for garbage collection.

You can overwrite the rule with useInstance(null) and the injector should no longer hold a reference to someOtherObj. There's currently no way to "delete" a rule, but that'd be very easy to add...

-Josh

2009/3/23 dtyrell <Dar...@gmail.com>



--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  jo...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

dtyrell

unread,
Mar 23, 2009, 4:33:29 AM3/23/09
to Smartypants IOC
Awesome! Perfect, I'll null 'em then.

I think it might be useful to be able to remove rules. Even if just
for "completeness" sake (although I certainly have real uses for it).

Cheers,

On Mar 23, 10:13 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> For 1 & 2, the new rule should overwrite the old, and someObj should become
> available for garbage collection.
>
> You can overwrite the rule with useInstance(null) and the injector should no
> longer hold a reference to someOtherObj. There's currently no way to
> "delete" a rule, but that'd be very easy to add...
>
> -Josh
>
> 2009/3/23 dtyrell <Dars...@gmail.com>
>
>
>
>
>
> > Greetings,
>
> > 3 new questions today:
>
> > 1) Do duplicate rules on the same Injector get "overwritten"?
>
> > injector.newRule().whenAskedFor( SomeClass ).useInstance( someObj );
> > injector.newRule().whenAskedFor( SomeClass ).useInstance
> > ( someOtherObj );
>
> > 2) Assuming there are no other references to someObj, will it be free
> > for Garbage Collection at this point?
>
> > 3) How might I free someOtherObj for GC later?
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald
>   -  j...@joshmcdonald.info

Josh McDonald

unread,
Mar 23, 2009, 4:50:01 AM3/23/09
to smartyp...@googlegroups.com
I'll put it in for 1.0, it's 20 minutes' work :)

2009/3/23 dtyrell <Dar...@gmail.com>
  -  jo...@joshmcdonald.info

dtyrell

unread,
Mar 23, 2009, 5:01:21 AM3/23/09
to Smartypants IOC
Legend!

On Mar 23, 10:50 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> I'll put it in for 1.0, it's 20 minutes' work :)
>
> 2009/3/23 dtyrell <Dars...@gmail.com>
Reply all
Reply to author
Forward
0 new messages