WeakReference Object


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: WeakReference Object

  1. #1
    Otis Guest

    WeakReference Object

    Hi,

    The WeakReference class lets a child object have a reference to it's parent
    without upping the reference count in the parent. I had the implementation
    screwed up and now it works OK. You can get the class and docs here:
    http://www.vtsoftware.co.uk/tools/circular.htm. There is a good discussion
    about this with an alternative method in 'Advanced Visual Basic 6' by Mathew
    Curland.

    I'm still trying to figure out how to reclaim that first chunk of memory
    after forms are loaded.

    Otis



    "Daniel Reber" <dreber@nospam.dminconline.com> wrote in message
    news:3e1488dc@tnews.web.devx.com...
    > what do you mean by "using the weak reference object."
    >
    > Thanks
    >
    > Daniel Reber
    >
    >
    > "Otis" <stephenprescott@msn.com> wrote in message
    > news:3e14857f$1@tnews.web.devx.com...
    > > Hi,
    > >
    > > Putting code back into classes was not the solution. When I did that, I
    > > inadvertantly removed code setting the parent references using the weak
    > > reference object. When memory was released, I thought it was from

    shifting
    > > code back into the classes. It was actually from omitting the parent
    > > references. The parent references are causing the memory leak.
    > >
    > > Thanks again.
    > >
    > > Otis
    > >
    > >
    > > "Otis" <stephenprescott@msn.com> wrote in message
    > > news:3e1470da$1@tnews.web.devx.com...
    > > > Hello and Happy New Year,
    > > >
    > > > I have a couple of questions relating to memory leaks. My VB6 App was
    > > > ratcheting memory use up every time I opened a form. Memory would go

    up
    > on
    > > > open, stay there after closing then go up more when I opened it again

    > and
    > > so
    > > > forth. I found the problem (or part of it). I was initializing all

    class
    > > > objects by passing 'Me' to a 'SetSuperState' function in a standard

    > > module.
    > > > I was also setting a local object var (Dim objTemp as Object) in a

    > > standard
    > > > module function to initialize child objects of collection classes. I

    > > thought
    > > > this was all safe since Me is a param and the other var is locally

    > > declared.
    > > > But when I moved all that code back into the classes, the leak went

    > away.
    > > So
    > > > the first question is why is that? Why weren't those objects destroyed

    > > when
    > > > they went out of scope. There are no explicit circular references. All
    > > > parent references are a weak reference.
    > > >
    > > > Question number 2: I notice that I never really reclaim all memory

    after
    > a
    > > > form is unloaded even after the leak fix. e.g. at program start with

    > only
    > > > the MDI form open, memory use is 11MB (this is the compiled version).

    If
    > I
    > > > load a child form with it's data, memory use goes up to 19MB. Then

    when
    > I
    > > > unload that form, it goes down to 15MB. Subsequent loading and

    unloading
    > > > bounces the memory use back and forth within this boundary (with the

    > lower
    > > > boundary going up about 2 MB and staying there after the second

    loading)
    > > but
    > > > it never goes back to the original 11MB. In a simple test app, I have
    > > > noticed the same behavior. Is this a VB quirk or am I missing

    something.
    > > > This happens both when I load the form itself and when I load it as an
    > > > object variable. The form has 'Set Form1 = Nothing' in the QueryUnload
    > > > event.
    > > >
    > > > Thanks.
    > > >
    > > > Otis
    > > >
    > > >
    > > >

    > >
    > >

    >
    >




  2. #2
    Anthony Jones Guest

    Re: WeakReference Object

    >
    I'm still trying to figure out how to reclaim that first chunk of memory
    after forms are loaded.
    <

    I think this probably normal and desirable behaviour. An application which
    is constantly allocating and deallocating pages of memory isn't good.
    Something (maybe even below the VB runtime) decides not to release the extra
    memory because it is likely that it will need it again in the not too
    distant future. Your opening and closing subsequent child forms confirms
    its decision to be a correct one.

    Anthony.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center