Posted on

Runaway ArrayCollections

Recently, I was racking my brain trying to solve a problem I had with a DataGrid not refreshing data. It took me a while to find the reason, so to help someone else with the same problem, I decided to write about it.


I had an ArrayCollection of custom classes called Build. Those Build classes each had an ArrayCollection another custom class, Item. Item is simply a class with properties key and value. The collection of Items is called metadata. In the Build, I created a getter to go grab the Item from it’s metadata with the key “STATUS”. This way, I can have the datagrid display the properties of each Build as well as the value associated with the metadata Item that has a key of STATUS. Make sense?


I’d receive a collection of Build objects back from a web service I was polling routinely. After the first call, I’d compare Build id’s and just update the existing Build with the updated information. The problem was, the DataGrid wasn’t showing the updates to the STATUS even though I could introspect with the debugger and see that it was getting updated.


I found that when I first created a Build instance, I was creating an ArrayCollection to hold the metadata and assigning listeners to watch for changes. I did that to keep it updated. After assigning the listeners, I would go about creating an ArrayCollection of Items and assigning that ArrayCollection to the metadata property of the Build. Did you catch that? My listeners were now listening to an orphaned ArrayCollection.


Be careful of when you create your properties and assign your listeners. I hope someone out there will be saved a few hours by this little tidbit. :)

Leave a Reply

Your email address will not be published. Required fields are marked *