K
Kevin
All samples in Micoroft just mention that if a managed
type is used as a member in nongc class, for example:
gcroot<String*> is used to define a String managed member
variable. What if the managed object in unmanaged class is
just defined in a member function instead of a member
variable. For example:
// managed imports
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
// unmanaged C++ class
class CSimple
{
public:
void Foo();
};
CSimple::Foo()
{
String *test = new String(S"FOO Test");
// Or should test be defined as gcroot<String*>
String nospace = test->Replace(" ", "_");
// Or should nospace be defined as gcroot<String*>
too????
}
it compiles fine without gcroot<String*>, but is it safe
for GC collector, should I define nospace as
gcroot<String*>
Thanks very much for your help!
Kevin
type is used as a member in nongc class, for example:
gcroot<String*> is used to define a String managed member
variable. What if the managed object in unmanaged class is
just defined in a member function instead of a member
variable. For example:
// managed imports
#using <mscorlib.dll>
using namespace System;
using namespace System::Runtime::InteropServices;
// unmanaged C++ class
class CSimple
{
public:
void Foo();
};
CSimple::Foo()
{
String *test = new String(S"FOO Test");
// Or should test be defined as gcroot<String*>
String nospace = test->Replace(" ", "_");
// Or should nospace be defined as gcroot<String*>
too????
}
it compiles fine without gcroot<String*>, but is it safe
for GC collector, should I define nospace as
gcroot<String*>
Thanks very much for your help!
Kevin