www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2497] New: delete and null relationship needs more details

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497

           Summary: delete and null relationship needs more details
           Product: D
           Version: 2.021
          Platform: PC
               URL: http://www.digitalmars.com/d/2.0/expression.html#DeleteE
                    xpression
        OS/Version: Linux
            Status: NEW
          Keywords: spec
          Severity: normal
          Priority: P2
         Component: www.digitalmars.com
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: jlquinn optonline.net


1) 

A a = null;
delete a;

is this OK or not?

2) 

void do(A b) { delete b; }
A a = new A;
do(a);
if (a is null) { writefln("yes"); }

does a get reset to null or not?


-- 
Dec 06 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
         OS/Version|Linux                       |All




------- Comment #1 from smjg iname.com  2008-12-06 18:22 -------
1. Good question.

2. No, because do has no access to variable a.  However, it were declared as
ref, it would.

It does say
"The pointer, dynamic array, or reference is set to null  after the delete is
performed."

Notice the singular.


-- 
Dec 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497





------- Comment #2 from jlquinn optonline.net  2008-12-06 18:49 -------
(In reply to comment #1)

 2. No, because do has no access to variable a.  However, it were declared as
 ref, it would.

OK, this is what I thought. What happens when you access a, then? In Java you'd get an NPE. no matter how you try to access the object. Does it coredump or is there a defined behavior? --
Dec 06 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497





------- Comment #3 from jarrett.billingsley gmail.com  2008-12-06 19:00 -------
It's undefined.  Comparing to Java doesn't make much sense here, since the only
way an object can go away in Java is if no references refer to it, so there's
no way to have a reference to an object that has been collected.  

delete is sort of a "power user" tool for when you _know_ that there are no
other references to the object and want to help out the GC a bit, so it's going
to have sharp edges.


-- 
Dec 06 2008
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497





------- Comment #4 from jlquinn optonline.net  2008-12-06 23:23 -------
(In reply to comment #3)
 It's undefined.  Comparing to Java doesn't make much sense here, since the only
 way an object can go away in Java is if no references refer to it, so there's
 no way to have a reference to an object that has been collected.  

Fair enough. It would be useful to note that accessing a deleted class through the reference is undefined. Otherwise it might leave others guessing. --
Dec 06 2008