title: Where do std::bind-created functors live?
body: <p>A function pointer can point to anything from a free function, a function object, a wrapper over a member function call.</p>
  
  <p>However, the std::bind created functors can have state, as well as custom-created ones. Where that state is allocated, and who is deleting it? </p>
  
  <p>Consider the below example - will the state ( the number 10) be deleted when the vector is deleted? Who know to call a deleter on the functor, and no deleter on the function pointer?</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;functional&gt;
  #include &lt;vector&gt;
  using namespace std;
  using namespace std::placeholders;
  class Bar
  {
      public:
      void bar(int x, int y) { cout &lt;&lt; "bar" &lt;&lt; endl; }
  };
  void foo(int baz){ cout &lt;&lt; "foo" &lt;&lt; endl; }
  int main() {
      typedef std::function&lt;void(int)&gt; Func;
  
      std::vector&lt;Func&gt; funcs;
      funcs.push_back(&amp;foo); // foo does not have to be deleted
      Bar b;
      // the on-the-fly functor created by bind has to be deleted
      funcs.push_back(std::bind(&amp;Bar::bar, &amp;b, 10, _1)); 
  
      // bind creates a copy of 10. 
      // That copy does not go into the vector, because it's a vector of pointers.
      // Where does it reside? Who deletes it after funcs is destroyed?
  
      return 0;
  }
  </code></pre>