title: pybind11 bad_alloc problem with std::vector<std::shared_ptr<A>>
body: <p>I have structs like this:</p>
  
  <pre><code>struct A{
    void do_stuff(){...does stuff};
  }
  struct B{
    std::vector&lt;std::shared_ptr&lt;A&gt;&gt; objs;
  }
  </code></pre>
  
  <p>my pybind:</p>
  
  <pre><code>py::class_&lt;A&gt;(m, "A")
    .def("do_stuff", &amp;A::do_stuff)
  py::class_&lt;B&gt;(m, "B")
    .def_readwrite("objs", &amp;B::objs);
  </code></pre>
  
  <p>Behaviour I'm trying to reach:</p>
  
  <pre><code>import mybind
  
  b_instance = mybind.B()
  
  for a_instance in b_instance:
    a_instance.do_stuff()
  </code></pre>
  
  <p>Unfortunately, I get </p>
  
  <blockquote>
    <p>MemoryError: std::bad_alloc</p>
  </blockquote>
  
  <p>Please, help me out.
  Code above is not actually the code I work with. Class A works by itself, but doesn't when iterating through B. If this code is not enough please write in the comments. Thanks!</p>