So I have this base component, that when running profiler, says its eating up tons of memory. I have about 4000 of these at one time in my Flex app (see component code below). This base component is extended by two other components, which are then extended by two more components each so 3 or 4 levels above this base component.
1. My first question is does the profiler just point to the base class or are there actually 4000 of these being created outside of their extended children? 2. My 2nd question is is their anything wrong with the code below? Why is it eatin memory? The parameter "content" when pulled in is a swf file (icon) that is 5kb each so 5kb * 4000... you get the math. When I run this progam the CarouselImage's are using up 30% to 35% of my apps memory usage. And my app is eating up 725,000kb of mem usage, thus crashing my pretty decent computer. // ----------- BEGIN CODE -------------------------------------- package com.mysite.views.components { import flash.display.DisplayObject; import flash.system.ApplicationDomain; import mx.core.UIComponent; import mx.events.ResizeEvent; public class CarouselImage extends UIComponent { // Content private var _content:DisplayObject; private var _contentWidth:Number; private var _contentHeight:Number; public function CarouselImage(content:*=null) { super(); // Set content this.content = content; } // Properties [Inspectable] public function get content():DisplayObject { return _content; } public function set content(value:*):void { if (_content != null) { removeChild(_content) removeEventListener(ResizeEvent.RESIZE, handleResize); } if (value is String) { try { value = ApplicationDomain.currentDomain.getDefinition(value); } catch (error:*) { // Do nothing } } if (value is Class) value = new value(); _content = value as DisplayObject; if (_content != null) { _contentWidth = _content.width; _contentHeight = _content.height; addChild(_content); addEventListener(ResizeEvent.RESIZE, handleResize); scaleContent(); } this.invalidateDisplayList(); this.invalidateProperties(); this.invalidateSize(); } public function get contentWidth():Number { return _contentWidth; } public function get contentHeight():Number { return _contentHeight; } // Measure and draw private function scaleContent():void { if (_content != null && width > 0 && height > 0) { // Width _content.scaleX = width / contentWidth; // Center the image _content.x = (width - (contentWidth * _content.scaleX)) * 0.5; // Height _content.scaleY = height / contentHeight; // Center the image _content.y = (height - (contentHeight * _content.scaleY)) * 0.5; } } // Event handlers private function handleResize(event:ResizeEvent):void { scaleContent(); this.invalidateDisplayList(); this.invalidateProperties(); this.invalidateSize(); } } } // ----------------- END CODE ------------------------------------