elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  Destructores y finalizadores en C++/CLI
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Destructores y finalizadores en C++/CLI  (Leído 1,420 veces)
SARGE553413

Desconectado Desconectado

Mensajes: 176


Ver Perfil
Destructores y finalizadores en C++/CLI
« en: 22 Agosto 2014, 14:38 pm »

Hola a todos. Escribo para comprobar si yo he entendido bien lo que son los destructores y los finalizadores en C++/CLI y cuál es su cometido.

Entiendo que el finalizador borra los recursos no administrados y el destructor borra los administrados y llama al finalizador (borra todo vamos).

Tengo dudas con variables estáticas y clases Singleton, expongo un pequeño ejemplo y me corregís.

Código:
ref class A{
public:
static A^ getInstance(){
if(INSTANCE==nullptr)
INSTANCE=gcnew INSTANCE();
return INSTANCE;
}

void destroyInstance(){
delete INSTANCE;
}

...
private:
int n;
char **c;
unsigned char *d;
String ^str;
Int32 ^intptr;
array<String^> ^aS;
Int32 num;

A(){
this->n=0;
this->c=new char*[10];
for(int i=0;i<10;i++) this->c[i]=new char[100];
this->d=new unsigned char[20];
this->str=gcnew String("A");
this->intptr=gcnew IntPtr();
this->aS=gcnew String^[100];
for(int i=0;i<100;i++) this->aS[i]=gcnew String();
this->num=1;
}

!A(){
for(int i=0;i<10;i++){
delete[] this->c;
this->c=NULL;
}
delete[] this->c;
this->c=NULL;
delete[] this->d;
this->d=NULL;
}

~A(){
this->!A();
delete this->str;
this->str=nullptr;
delete this->intptr;
this->intptr=nullptr;
for(int i=0;i<100;i++){
delete this->aS[i];
this->aS[i]=nullptr;
}
}
}

PD. Para recursos estáticos, tanto administrados como no, ¿exactamente igual?

Gracias, saludos.


En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines