G
Guest
but ireally does need clearing up ...
Traditionally (i.e. in C++) I might do the following:
SomeObj ptrSomeObj;
for(int i = 0; i < iCount; ++i)
{
ptrSomeObj = new SomeObj();
ptrSomeObj->MethodOne();
delete ptrSomeObj;
}
Now, as far as I'm aware, the equivalent code in C# is this:
SomeObj myObj;
for(int i = 0; i < iCount; ++i)
{
myObj = new SomeObj();
myObj.MethodOne();
}
Now the question comes ....
traditionally, I would declare my pointer OUTSIDE of the for loop (for
obvious reasons), but whilst reviewing code produced by several "seasoned"
developers, their C# code does the opposite, for example:
for(int i = 0; i < iCount; ++i)
{
SomeObj myObj = new SomeObj();
myObj.MethodOne();
}
what I want to know is, yes, we are using a managed heap, but that doesn't
necessarily make that last bit of code any more acceptable does it?
Or am I completely wrong.
Traditionally (i.e. in C++) I might do the following:
SomeObj ptrSomeObj;
for(int i = 0; i < iCount; ++i)
{
ptrSomeObj = new SomeObj();
ptrSomeObj->MethodOne();
delete ptrSomeObj;
}
Now, as far as I'm aware, the equivalent code in C# is this:
SomeObj myObj;
for(int i = 0; i < iCount; ++i)
{
myObj = new SomeObj();
myObj.MethodOne();
}
Now the question comes ....
traditionally, I would declare my pointer OUTSIDE of the for loop (for
obvious reasons), but whilst reviewing code produced by several "seasoned"
developers, their C# code does the opposite, for example:
for(int i = 0; i < iCount; ++i)
{
SomeObj myObj = new SomeObj();
myObj.MethodOne();
}
what I want to know is, yes, we are using a managed heap, but that doesn't
necessarily make that last bit of code any more acceptable does it?
Or am I completely wrong.