|
|
| Author |
Message |
Edward Guest
|
Posted: Mon Nov 22, 2004 3:34 pm Post subject: managed code? |
|
|
I was going through the examples in the C# book for 316. As a VB6.0, Fortran
and C++ programmer I was troubled by what I was doing. Below is a short
example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects on the
heap and ignore them when you are done? Will they be taken care of when the
system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward |
|
| Back to top |
|
 |
|
|
Edward Guest
|
Posted: Mon Nov 22, 2004 3:34 pm Post subject: Re: managed code? |
|
|
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (p); // forgot to change this variable to p also
Edward sorry
}
"Edward" <elongcore@news.net> wrote in message
news:O4rkCIK0EHA.1400@TK2MSFTNGP11.phx.gbl...
| Quote: | I was going through the examples in the C# book for 316. As a VB6.0,
Fortran and C++ programmer I was troubled by what I was doing. Below is a
short example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects on
the heap and ignore them when you are done? Will they be taken care of
when the system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward
|
|
|
| Back to top |
|
 |
Nick Guest
|
Posted: Tue Nov 23, 2004 10:33 am Post subject: Re: managed code? |
|
|
Yep, that should be ok afaik.
The difficulty comes when you are using types defined in unmanaged code.
Then you have to implement the dispose pattern and clean up after yourself.
"Edward" <elongcore@news.net> wrote in message
news:e7fDYOK0EHA.2528@TK2MSFTNGP10.phx.gbl...
| Quote: | for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (p); // forgot to change this variable to p also
Edward sorry
}
"Edward" <elongcore@news.net> wrote in message
news:O4rkCIK0EHA.1400@TK2MSFTNGP11.phx.gbl...
I was going through the examples in the C# book for 316. As a VB6.0,
Fortran and C++ programmer I was troubled by what I was doing. Below is a
short example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects on
the heap and ignore them when you are done? Will they be taken care of
when the system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward
|
|
|
| Back to top |
|
 |
Edward Guest
|
Posted: Tue Nov 23, 2004 2:38 pm Post subject: Re: managed code? |
|
|
Well after years and years of cleaning up after myself, this managed code
just makes me nervous.
"Nick" <someone@somewhere.com> wrote in message
news:e$g9h9T0EHA.2568@TK2MSFTNGP11.phx.gbl...
| Quote: | Yep, that should be ok afaik.
The difficulty comes when you are using types defined in unmanaged code.
Then you have to implement the dispose pattern and clean up after
yourself.
"Edward" <elongcore@news.net> wrote in message
news:e7fDYOK0EHA.2528@TK2MSFTNGP10.phx.gbl...
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (p); // forgot to change this variable to p
also Edward sorry
}
"Edward" <elongcore@news.net> wrote in message
news:O4rkCIK0EHA.1400@TK2MSFTNGP11.phx.gbl...
I was going through the examples in the C# book for 316. As a VB6.0,
Fortran and C++ programmer I was troubled by what I was doing. Below is a
short example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects on
the heap and ignore them when you are done? Will they be taken care of
when the system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward
|
|
|
| Back to top |
|
 |
Jon Goodwin Guest
|
Posted: Tue Nov 23, 2004 5:36 pm Post subject: Re: managed code? |
|
|
Edward,
Have a look at the following URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp
It explains how .NET implements garbage collection and why you should
never need to worry about cleaning up after yourself again!
Edward wrote:
| Quote: | Well after years and years of cleaning up after myself, this managed code
just makes me nervous.
"Nick" <someone@somewhere.com> wrote in message
news:e$g9h9T0EHA.2568@TK2MSFTNGP11.phx.gbl...
Yep, that should be ok afaik.
The difficulty comes when you are using types defined in unmanaged code.
Then you have to implement the dispose pattern and clean up after
yourself.
"Edward" <elongcore@news.net> wrote in message
news:e7fDYOK0EHA.2528@TK2MSFTNGP10.phx.gbl...
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (p); // forgot to change this variable to p
also Edward sorry
}
"Edward" <elongcore@news.net> wrote in message
news:O4rkCIK0EHA.1400@TK2MSFTNGP11.phx.gbl...
I was going through the examples in the C# book for 316. As a VB6.0,
Fortran and C++ programmer I was troubled by what I was doing. Below is a
short example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects on
the heap and ignore them when you are done? Will they be taken care of
when the system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward
|
|
|
| Back to top |
|
 |
clyclopedic Guest
|
Posted: Tue Nov 23, 2004 10:40 pm Post subject: Re: managed code? |
|
|
I haven't watched it yet, but from the blurbs I think you might also be
interested in the Jason Zander interview posted to channel 9 today
http://channel9.msdn.com/
"Jon Goodwin" <jon@rocketwebservices.co.uk> wrote in message
news:OLIrYHY0EHA.3832@TK2MSFTNGP10.phx.gbl...
| Quote: | Edward,
Have a look at the following URL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/dotnetGCbasics.asp
It explains how .NET implements garbage collection and why you should
never need to worry about cleaning up after yourself again!
Edward wrote:
Well after years and years of cleaning up after myself, this managed code
just makes me nervous.
"Nick" <someone@somewhere.com> wrote in message
news:e$g9h9T0EHA.2568@TK2MSFTNGP11.phx.gbl...
Yep, that should be ok afaik.
The difficulty comes when you are using types defined in unmanaged code.
Then you have to implement the dispose pattern and clean up after
yourself.
"Edward" <elongcore@news.net> wrote in message
news:e7fDYOK0EHA.2528@TK2MSFTNGP10.phx.gbl...
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (p); // forgot to change this variable to p
also Edward sorry
}
"Edward" <elongcore@news.net> wrote in message
news:O4rkCIK0EHA.1400@TK2MSFTNGP11.phx.gbl...
I was going through the examples in the C# book for 316. As a VB6.0,
Fortran and C++ programmer I was troubled by what I was doing. Below is
a short example I wrote to demonstrate my puzzlement.
Is this good coding in a managed environment? Just create new objects
on the heap and ignore them when you are done? Will they be taken care
of when the system does clean up? Shouldn't I destroy them myself?
for (int i = 0 ; i < 10; i++)
{
int p = new int();
p = i;
System.Console.WriteLine (place);
}
Thanks for the help
Edward
|
|
|
| Back to top |
|
 |
|