Reputation: 1527
I have a simple question but i am confused so asking. What is difference between these two scenarios.
1)
DataSet ds = getUsers();
2)
DataSet ds = new DataSet();
ds = getUsers();
Upvotes: 2
Views: 101
Reputation: 6260
In version 1 here's what happens:
getUsers
creates a new DataSet
object.ds
.In version 2 here's what happens:
DataSet
object is instantiated and the reference to it is stored in ds
.getUsers
creates a different DataSet
object.DataSet
gets stored in ds
.DataSet
now no longer has any variables referencing it and will be picked up by the garbage collector.Upvotes: 4
Reputation: 43254
Version (2) creates a new DataSet then hands it over to be garbage collected. Aside from that, they are the same.
Upvotes: 4