FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Bug deleting form

 
Post new topic   Reply to topic     Forum Index -> DFL
View previous topic :: View next topic  
Author Message
jvr



Joined: 19 Nov 2007
Posts: 10

PostPosted: Thu Feb 07, 2008 11:53 am    Post subject: Bug deleting form Reply with quote

Hi,

I need to delete the forms to release some GDI handles but there is a problem, an access violation, here a minimal example that generates the error:

Code:

import dfl.all;
import std.stdio;

// ---------------------------------------------------------------------
class MyControl
{
private:
  PictureBox m_picbox;

public:
  this(Control parent )
  {
    writefln("MyControl Constructor");
   
    m_picbox = new PictureBox;
    m_picbox.parent = parent;
  }
 
  ~this()
  {
    writefln("MyControl Destructor");

    m_picbox.dispose();
  }
}

// ---------------------------------------------------------------------
class MyForm : Form
{
private:
  MyControl m_my_control;
 
public:
  this()
  {
    writefln("MyForm Constructor");
   
    m_my_control = new MyControl(this);
  }
 
  ~this()
  {
    writefln("MyForm Destructor");
   
    // If you uncomment the next line then the problem is solved, why?
    // delete m_my_control;
  }
}

// ---------------------------------------------------------------------
int main()
{
   MyForm my_form = new MyForm;
   
   Application.run(my_form);
   
   delete my_form;
   
   return(0);
}



The output is:

MyForm Constructor
MyControl Constructor
MyForm Destructor
MyControl Destructor
Error: Access Violation

And, how can I know the code that produced the access violation?

Thanks, cheers
Javi

P.S. I'm using DMD 1.026
Back to top
View user's profile Send private message
Chris Miller



Joined: 27 Mar 2004
Posts: 514
Location: The Internet

PostPosted: Mon Feb 18, 2008 2:29 am    Post subject: Re: Bug deleting form Reply with quote

You're not really supposed to do that in D (access a GC'd class field in a destructor)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> DFL All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group