How to get the memory size of an ArrayCollection in Flex
I have built an image ca开发者_JAVA技巧che which is an ArrayCollection containing images. I have built functionality so that the cache can hold a max of 250 images. However, the images can be of a different size, so it's better to limit the total memory size of all images in the ArrayCollection.
Does anyone know how I can get the total memory size of an ArrayCollection without looping through all the items in the ArrayCollection?
I'm not sure you can. My advice is to create a new collection class based on ArrayCollection (say, ImageCacheCollection) that keeps track of the collection's current memory size and its memory limit. Before you add an image to the collection you first verify that the memory limit won't be exceeded. If it isn't, you add the image to the collection, in the process adding the image's file size to the collection's current memory size.
精彩评论