#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    20
    Rep Power
    0

    deleting references from the free store.


    ok, this book i am reading says the references cannot be null, but leaving them can create memory leakage. so how exactly do i delete them and prevent memory leakage? heres what the book says but i do not understand it:

    The third workable solution, and the right one, is to declare the object in the calling function and then to pass it to TheFunction() by reference.

    The best I can interprete it is to create the object within the function, and then return the value of that object with a reference to the object. how does this delete the reference? is it that, since it points to a local variable, it gets deleted when the function ends? a lot of that i just thought up of now :D So did I get that right? I dont want to guess and get it wrong because the book scares me in the ways it talks about invalid programs :eek:
  2. #2
  3. No Profile Picture
    status unknown
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    262
    Rep Power
    12
    Can you show us the context in which it says that leaving references can create memory leakage?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    20
    Rep Power
    0
    >> To prove that the reference declared in main() is referring to the object put on the free store in TheFunction(), the address of operator is applied to rCat(the reference object). Sure enough, it displays the address of the object it refers to and this matches the address of the object on the free store.

    So far, so good. But how will that memory be freed? You can't call delete on the reference.

    So I figure you have to do something that will have the same effect as delete, which is freeing up memory on the free store, correct?
    It relates to an example but I hope you can figure out what it means. It just calls the address operator on an object and a reference, and it displays the same address, meaning that the reference at least refers to something on the free store.

IMN logo majestic logo threadwatch logo seochat tools logo