[Issue 9433] Deprecate delete
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 31 07:14:08 PST 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9433
FG <home at fgda.pl> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |home at fgda.pl
--- Comment #1 from FG <home at fgda.pl> 2013-01-31 07:14:06 PST ---
(In reply to comment #0)
> But I expect a message like:
> temp.d(5): Deprecation: use of delete is deprecated; use destroy (and
> core_memory.GC.free) instead.
Delete cannot be deprecated because there is no properly working replacement
for delete at this moment. Look at the following code:
import std.stdio, core.memory;
class C {
byte[] s;
this() { s = new byte[40 * 1024 * 1024]; }
}
void main(string[] args) {
for (int i=0, j=0; i < 1000; i++) {
auto x = new C();
// delete x.s; // A
// x.s.destroy(); // B
// GC.free(cast(void*)x.s); // C
}
}
Let's see memory usage on windows when line A, B or C get uncommented, with
code compiled using DMD32 v2.060 and GDC (tmd64-1) 4.6.1:
code | dmd32 | gdc64
- | OOM | 160MB
A | 40MB | 40MB
B | OOM | 160MB
B+C | OOM | 160MB
C | 40MB | 40MB
where OOM = OutOfMemoryError and 160MB is sometimes 120MB.
Only lines A and C are acceptable memory-wise but C doesn't run destructors.
Combining C with B calls destructors but doesn't free memory. Even the manual
for core.memory.free tells to use delete in such cases! So how can you get rid
of delete?
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list