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





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








 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






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 next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497







 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
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497




Commit pushed to
https://github.com/D-Programming-Language/d-programming-language.org

https://github.com/D-Programming-Language/d-programming-language.org/commit/59d36352183e14ea08c4e64853a6f20a7112a3d4
fix Issue 2497 - delete and null relationship needs more details

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2497


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 22 2012