A private list variable is inadvertently shared between instance objects
<p>I created many instances of a <code>PlotHandler</code> class. An instance must keep it's variables private. But the way I managed them led to a hard to detect problem, <strong>a private list variable is shared between instances</strong>! And that too without any obvious source for the leak.</p>

<p>My debugging told me that the private member function that modifies the list sees the same list, even if they are different objects.</p>

<p>Is this a "gotcha" problem? What is the best way to troubleshoot this?</p>

<hr>

<p>Here are the relevant parts (I hope they are!) of the implementation. Please see the ALL-CAPS comments: </p>

<p>The file implementing PlotHandler:</p>

<pre><code>class PlotHandler(wx.Frame):
    __crop_section = None
    __projection   = None
    __crop_xcord   = None

    _band_data     = [] #THIS GETS SHARED

def _on_plot_click(self, xcord): #CALLED BY ANOTHER OBJECT
    band = self._analyze_band( xcord )
    self._band_data.append(band)
    ...
</code></pre>

<p>The parent class that it is managing PlotHandlers:</p>

<pre><code>class MainFrame(wx.Frame):
    __close_callback__ = None
    _plot_handlers     = []
    def __init__(self, parent, title):
        ...


    def InitUI(self):
        ...

        img_handler = ImageHandler(panel)
        self.img_src.register_callback( img_handler.update_image )

        #you need to call PlotHandler(parent, cropped)
        img_handler.register_sample_callback( self._create_new_plot_handler )

        ...

    def _create_new_plot_handler(self, cropped_sample ):
    self._plot_handlers.append( PlotHandler(self, cropped_sample) ) #CREATE THEM
</code></pre>
