Xcode memory leak detection for c++ command line app -


i'm trying use leaks instrument detect memory leaks in linked list implemented.

here code -

#ifndef linkedlist_h #define linkedlist_h  #include <initializer_list> #include <iostream> #include <stdexcept>  using std::runtime_error; using std::initializer_list; using std::ostream;  template <typename t> class linkedlist {     template <typename u>     friend ostream& operator<<(ostream &, const linkedlist<u> &); public:      typedef t value_type;     typedef int size_type;  private:      struct node {         t value;         node *next;         node *prev;     };      node *head;     node *tail;      size_type n_elems;  public:      linkedlist();     linkedlist(std::initializer_list<t> il);     ~linkedlist();      size_type size() const;      bool empty() const;      void push_front(const t&);     void push_back(const t&);     void pop_back();     void pop_front();      t& front() const;     t& back() const; };  template <typename t> ostream& operator<<(ostream&, const linkedlist<t> &);  template <typename t> linkedlist<t>::linkedlist() : head(nullptr), tail(nullptr), n_elems(0) { }  template <typename t> linkedlist<t>::linkedlist(std::initializer_list<t> il) : head(nullptr), tail(nullptr), n_elems(0) {     // insert elements list here     // re-use insert operation after implementing     for(auto &elem: il) {         push_back(elem);     } }  template <typename t> t& linkedlist<t>::back() const {     if(tail == nullptr)         throw runtime_error("back() on empty linkedlist!\n");      return tail->value; }  template <typename t> t& linkedlist<t>::front() const {     if(head == nullptr)         throw runtime_error("front() on empty linkedlist!\n");      return head->value; }  template <typename t> typename linkedlist<t>::size_type linkedlist<t>::size() const {     return n_elems; }  template <typename t> bool linkedlist<t>::empty() const {     return n_elems == 0; }  template <typename t> void linkedlist<t>::push_front(const t& elem) {     node *new_node = new node;     new_node->value = elem;     new_node->next = nullptr;     new_node->prev = nullptr;      if(head == nullptr) {         head = tail = new_node;         ++n_elems;         return;     }      new_node->next = head;     head->prev = new_node;     head = new_node;      ++n_elems; }  template <typename t> void linkedlist<t>::push_back(const t& elem) {     node *new_node = new node;     new_node->value = elem;     new_node->next = nullptr;     new_node->prev = nullptr;      if(tail == nullptr) {         head = tail = new_node;         ++n_elems;         return;     }      new_node->prev = tail;     tail->next = new_node;     tail = new_node;      ++n_elems; }  template <typename t> void linkedlist<t>::pop_back() {     if(tail == nullptr)         throw runtime_error("pop_back() on empty linkedlist\n");      if(head == tail) {         delete head;         head = tail = nullptr;         --n_elems;         return;     }      node *to_remove = tail;     to_remove->prev->next = nullptr;     tail = to_remove->prev;      delete to_remove;      --n_elems; }  template <typename t> void linkedlist<t>::pop_front() {     if(head == nullptr)         throw runtime_error("pop_front() on empty linkedlist\n");      if(head == tail) {         delete head;         head = tail = nullptr;         --n_elems;         return;     }      node *to_remove = head;     to_remove->next->prev = nullptr;     head = to_remove->next;      delete to_remove;      --n_elems; }  template <typename t> ostream& operator<<(ostream &out, const linkedlist<t> &list) {     typename linkedlist<t>::node *crawler = list.head;      while(crawler != nullptr) {         out << crawler->value << " ";         crawler = crawler->next;     }      return out; }  template <typename t> linkedlist<t>::~linkedlist(){     typename linkedlist<t>::node *crawler = head;      while(crawler != nullptr) {         auto *next = crawler->next;         delete crawler;         crawler = next;     } }   #endif /* linkedlist_h */ 

here driver program -

#include <iostream> #include "linkedlist.h"  using std::cout; using std::cin; using std::endl;  int main(void) {     linkedlist<int> int_list;      for(int = 0; < 10; ++i) {         int_list.push_back(i);     }      cout << int_list.size() << endl;     cout << int_list << endl;      for(int = 0; < 8; ++i)         int_list.pop_front();      cout << int_list << endl;     cout << int_list.size() << endl;      int_list.pop_back();      cout << int_list << endl;      int *myint = new int;     *myint = 0;      myint = nullptr;      return 0; } 

now when try product->profile->leaks , press record button nothing happens. timer stays @ 00.

here picture -

screenshot of profiler. can please tell me what's going wrong here? missing steps?

i deliberately added leaks end of driver program still nothing seems happen. need regarding this.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -