Doing one last thing to a WeakReference - Java

This is a discussion on Doing one last thing to a WeakReference - Java ; Stefan Ram wrote: > Tom Anderson <twic@urchin.earth.li> writes: >> I think the best accomodation that could be made without a major and >> potentially awkward addition to the language and runtime system would be a >> C#-style 'using' construct: >> ...

+ Reply to Thread
Page 8 of 8 FirstFirst ... 6 7 8
Results 71 to 75 of 75

Doing one last thing to a WeakReference

  1. Default Re: Doing one last thing to a WeakReference

    Stefan Ram wrote:
    > Tom Anderson <twic@urchin.earth.li> writes:
    >> I think the best accomodation that could be made without a major and
    >> potentially awkward addition to the language and runtime system would be a
    >> C#-style 'using' construct:
    >> using (ImageInfo info = getImageInfo(fileName)) {
    >> int w = info.getWidth() ;
    >> // etc
    >> }

    >
    > In [1], it is described how to write a class
    > »FileInputStreamOpenCloseAndNull« so that
    >
    > for( final java.io.FileInputStream fileInputStream:
    > new FileInputStreamOpenCloseAndNull( "input.txt" ))
    > use( fileInputStream );
    >
    > will close »fileInputStream« after the use.


    The same can be achieved with a finally.

    Arne

  2. Default Re: Doing one last thing to a WeakReference

    John W Kennedy wrote:
    > Stefan Ram wrote:
    >> "Paul J. Lucas" <paul-nospam@nospam.lucasmail.org> writes:
    >>> It's a perfectly reasonable (and common) thing to want to:
    >>> a) guarantee an object is destroyed as soon as it's no longer used
    >>> (and not "some later time").
    >>> b) do one last thing to an object before it's destroyed.

    >>
    >> C++ has destructors.
    >>
    >> Are there any other (object-oriented) programming
    >> languages with destructors?

    >
    > Turbo Pascal did; I suppose Delphi does. I daresay any OO language that
    > has either a FREE statement/operator or stack-allocated objects will,
    > perforce.


    All languages with dynamic allocation and no GC, which probably
    is about the same as your criteria.

    Ada must fell in this category as well.

    Arne



  3. Default Re: Doing one last thing to a WeakReference

    John B. Matthews wrote:
    > In article <48642af2$0$5019$607ed4bc@cv.net>,
    > John W Kennedy <jwkenne@attglobal.net> wrote:
    >> Stefan Ram wrote:
    >>> "Paul J. Lucas" <paul-nospam@nospam.lucasmail.org> writes:
    >>>> It's a perfectly reasonable (and common) thing to want to:
    >>>> a) guarantee an object is destroyed as soon as it's no longer used
    >>>> (and not "some later time").
    >>>> b) do one last thing to an object before it's destroyed.
    >>> C++ has destructors.
    >>>
    >>> Are there any other (object-oriented) programming
    >>> languages with destructors?

    >> Turbo Pascal did; I suppose Delphi does. I daresay any OO language that
    >> has either a FREE statement/operator or stack-allocated objects will,
    >> perforce.

    >
    > As did Wirth's Object Pascal, but I'm not sure free qualifies as a
    > destructor. In contrast, what the OP wants is a user-defined method that
    > is called when the storage is actually reclaimed, but at a more
    > deterministic time than finalize().


    I don't think the argument was that free was a destructor - just that
    a language that used free would need a destructor.

    Arne

  4. Default Re: Doing one last thing to a WeakReference

    In article <4865b356$0$90262$14726298@news.sunsite.dk>,
    Arne Vajhøj <arne@vajhoej.dk> wrote:

    > John B. Matthews wrote:
    > > In article <48642af2$0$5019$607ed4bc@cv.net>,
    > > John W Kennedy <jwkenne@attglobal.net> wrote:
    > >> Stefan Ram wrote:
    > >>> "Paul J. Lucas" <paul-nospam@nospam.lucasmail.org> writes:
    > >>>> It's a perfectly reasonable (and common) thing to want to:
    > >>>> a) guarantee an object is destroyed as soon as it's no longer used
    > >>>> (and not "some later time").
    > >>>> b) do one last thing to an object before it's destroyed.
    > >>> C++ has destructors.
    > >>>
    > >>> Are there any other (object-oriented) programming
    > >>> languages with destructors?
    > >> Turbo Pascal did; I suppose Delphi does. I daresay any OO language that
    > >> has either a FREE statement/operator or stack-allocated objects will,
    > >> perforce.

    > >
    > > As did Wirth's Object Pascal, but I'm not sure free qualifies as a
    > > destructor. In contrast, what the OP wants is a user-defined method that
    > > is called when the storage is actually reclaimed, but at a more
    > > deterministic time than finalize().

    >
    > I don't think the argument was that free was a destructor - just that
    > a language that used free would need a destructor.


    Yes, but the utility was apparent only in retrospect. All the languages
    mentioned (Ada, C++, D, Delphi, Java, Object Pascal, Turbo Pascal) are
    object-oriented and have destructors in the sense of a method that is
    automatically invoked when the object's storage is reclaimed.
    Conversely, not all object-oriented languages that can reclaim storage
    (by freeing dynamically allocated memory or closing a stack frame) have
    the method invocation characteristic of destructors. Wirth & Tessler's
    original Object Pascal is a familiar counter-example. IIRC, Turbo Pascal
    had just a single destructor.

    --
    John B. Matthews
    trashgod at gmail dot com
    home dot woh dot rr dot com slash jbmatthews

  5. Default Re: Doing one last thing to a WeakReference

    Arne Vajhøj wrote:
    > Stefan Ram wrote:
    >> In [1], it is described how to write a class
    >> »FileInputStreamOpenCloseAndNull« so that
    >>
    >> for( final java.io.FileInputStream fileInputStream:
    >> new FileInputStreamOpenCloseAndNull( "input.txt" ))
    >> use( fileInputStream );
    >>
    >> will close »fileInputStream« after the use.

    >
    > The same can be achieved with a finally.


    Except if "after the use" is not lexically scoped.

    - Paul

+ Reply to Thread
Page 8 of 8 FirstFirst ... 6 7 8