【发布时间】:2014-09-14 05:43:33
【问题描述】:
来自官方 D 书:
import std.stdio;
void main()
{
double[] slice1 = [ 1, 1, 1 ];
double[] slice2 = [ 2, 2, 2 ];
double[] slice3 = [ 3, 3, 3 ];
slice2 = slice1; // ← slice2 starts providing access
// to the same elements that
// slice1 provides access to
slice3[] = slice1; // ← the values of the elements of
// slice3 change
writeln("slice1 before: ", slice1);
writeln("slice2 before: ", slice2);
writeln("slice3 before: ", slice3);
slice2[0] = 42; // ← the value of an element that
// it shares with slice1 changes
slice3[0] = 43; // ← the value of an element that
// only it provides access to
// changes
writeln("slice1 after : ", slice1);
writeln("slice2 after : ", slice2);
writeln("slice3 after : ", slice3);
}
slice2是指向了一些数据,然后改成指向别的东西,这不是会导致内存泄漏吗?
【问题讨论】:
标签: memory-leaks d