IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

wxWidgets Discussion :

Problème de memory leaks


Sujet :

wxWidgets

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut Problème de memory leaks
    Bonjour!

    J'écris l'interface graphique d'une petite application et j'ai un problème de memory leaks.
    J'ai essayé pas mal de trucs mais je ne vois vraiment pas d'où ça vient.
    Quand je ferme la fenêtre principale, le compilateur m'envoie le message suivant :

    Detected memory leaks!
    Dumping objects ->
    {1480} normal block at 0x00DBFF60, 48 bytes long.
    Data: <$d w > 24 64 80 00 01 00 00 00 77 00 00 00 8D 00 00 00
    {1478} normal block at 0x00DC0E50, 8 bytes long.
    Data: <tG} ` > 74 47 7D 00 60 FF DB 00
    Object dump complete.

    Bon c'est pas grand chose me direz-vous, mais j'aimerais bien produire le code le plus propre possible.

    Voilà la déclaration des classes :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    // Declare the application class
    class MyApp : public wxApp
    {
    	public :
    		// Called on application startup
    		virtual bool OnInit();
    		virtual int OnExit();
    	private :
    		MyFrame* frame;
    		wxJPEGHandler* imageHandler;
    };
     
    // Declare our main frame class
    class MyFrame : public wxFrame
    {
    	public :
    		//Constructor
    		MyFrame(const wxString& title);
     
    		//Event handlers
    		void OnQuit(wxCommandEvent& event);
    		void OnButton(wxCommandEvent& event);
    		void OnLink(wxCommandEvent& event);
     
    	private:
    		// This class handles events
    		DECLARE_EVENT_TABLE()
     
    		//Attributes
    		wxArrayString choices;
    		wxPanel* panel;
    		wxBitmap* bitmap;
    		wxStaticBitmap* staticBitmap;
    		wxComboBox* comboBox;
    		wxButton* link;
    		wxButton* button;
    		wxBoxSizer* topSizer;
    };
    et leur implémentation (partielle):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    const int ID_COMBOBOX = 101;
    const int BUTTON2 = 102;
    const int BUTTON3 = 103;
     
    // Implements MyApp& GetApp()
    DECLARE_APP(MyApp)
     
    // Give wxWidgets the means to create a MyApp object
    IMPLEMENT_APP(MyApp)
     
    // Initialize the application
    bool MyApp::OnInit()
    {
    	imageHandler = new wxJPEGHandler;
    	wxImage::AddHandler(imageHandler);
     
    	// Create the main application window
    	frame = new MyFrame(wxT("Test"));
     
    	// Show it
    	frame->Show(true);
     
    	// Start the event loop
    	return true;
    }
     
    int MyApp::OnExit()
    {
    	return 0;
    }
     
    // Event table for MyFrame
    BEGIN_EVENT_TABLE(MyFrame, wxFrame)
    	EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
    	EVT_BUTTON(BUTTON2, MyFrame::OnButton)
    	EVT_BUTTON(BUTTON3, MyFrame::OnLink)
    END_EVENT_TABLE()
     
    void MyFrame::OnQuit(wxCommandEvent& event)
    {
    	// Destroy the frame
    	Close(true);
    }
     
    MyFrame::MyFrame(const wxString& title) : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxDefaultSize)
    {
    	choices.Add(wxT("Aymeric"));
    	choices.Add(wxT("Bruno"));
     
    	panel = new wxPanel(this);
     
    	panel->SetBackgroundColour(*wxWHITE);
     
    	topSizer = new wxBoxSizer(wxVERTICAL);
     
    	wxImage image(wxT("C:\\Documents and Settings\\Clément\\Bureau\\images.jpg"), wxBITMAP_TYPE_JPEG);
    	bitmap = new wxBitmap(image);
     
    	staticBitmap = new wxStaticBitmap(panel, wxID_STATIC, *bitmap, wxDefaultPosition, wxDefaultSize);
    	topSizer->Add(staticBitmap, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
     
    	comboBox = new wxComboBox(panel, ID_COMBOBOX, wxT("Aymeric"), wxDefaultPosition, wxDefaultSize, choices, wxCB_DROPDOWN);
    	topSizer->Add(comboBox, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
     
    	link = new wxButton(panel, BUTTON3, "Creation d'un nouveau profil");
    	link->SetForegroundColour(*wxBLUE);
    	link->SetWindowStyle(wxBORDER_NONE);
    	topSizer->Add(link, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
     
    	button = new wxButton(panel, BUTTON2, _T("Ok"), wxDefaultPosition, wxSize(50,30), wxID_JUSTIFY_CENTER);
    	topSizer->Add(button, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
     
    	topSizer->SetSizeHints(this);
    	SetSizer(topSizer);
    }
    Quelqu'un aurait une idée?

    Merci d'avance!

  2. #2
    Membre éclairé

    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    717
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2006
    Messages : 717
    Points : 858
    Points
    858
    Par défaut
    A priori cela vient du bitmap, qui est alloué mais jamais désalloué.

    D'ailleurs cette allocation dynamique est inutile, tu peux passer l'image directement au StaticBitmap, elle sera converti en bitmap automatiquement. Ensuite tu peux utiliser la fonction GetBitmap() du contrôle pour avoir accès au bitmap, si nécessaire.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 4
    Points : 5
    Points
    5
    Par défaut
    C'est bon ça marche!

    Merci beaucoup!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème memory leak
    Par donnadieujulien dans le forum Débuter
    Réponses: 13
    Dernier message: 26/05/2011, 12h07
  2. Problème de memory leak
    Par Tiberizz dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 19/05/2007, 17h11
  3. [MFC] A la chasse au memory leak
    Par Yabo dans le forum MFC
    Réponses: 17
    Dernier message: 27/06/2004, 17h35
  4. Réponses: 7
    Dernier message: 26/02/2004, 09h32
  5. Problème avec memory mapping
    Par gemai dans le forum C
    Réponses: 13
    Dernier message: 04/07/2003, 09h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo