# UIComponent memory issue

**URL:** <https://forum.kirupa.com/t/uicomponent-memory-issue/330261>\
**Category:** flash\
**Created:** [December 20, 2012, 1:01pm UTC](https://forum.kirupa.com/t/uicomponent-memory-issue/330261 "2012-12-20T13:01:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![destinier](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@destinier](https://forum.kirupa.com/u/destinier)\
**Post date:** [December 20, 2012, 1:01pm UTC](https://forum.kirupa.com/t/uicomponent-memory-issue/330261/1 "2012-12-20T13:01:49Z")

</div>

Hi all,

I have observed \*\*UIComponent \*\*and found some interesting thing. Please check the following code which is present in \*\*UIComponent \*\*constructor.

```php
addEventListener(Event.ADDED, addedHandler);
        addEventListener(Event.REMOVED, removedHandler);
        addEventListener(Event.REMOVED_FROM_STAGE, removedFromStageHandler);

        // Register for focus and keyboard events.
        if (this is IFocusManagerComponent)
        {
            addEventListener(FocusEvent.FOCUS_IN, focusInHandler);
            addEventListener(FocusEvent.FOCUS_OUT, focusOutHandler);
            addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
            addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
        }

```

We all know that every component in Flex is extended by this core class. And we also know that a display object (ex:any Flex component) can not be marked for garbage collection until all of its event listeners were removed.

Now my question is where does the above event listeners removed, I don’t see anywhere… more over “addedHandler” is private function, so the listener can not be removed in descendants, it has to be removed in UIComponent.as only. I have also observed the same behavior in Spark List component too, where they are adding a listener in constructor itself, but not removing same anywhere else.

```php
addEventListener(TouchInteractionEvent.TOUCH_INTERACTION_START, touchInteractionStartHandler);

```

Here again “touchInteractionStartHandler” is a private function.

So this means, every flex component is not garbage collected thus causing memory leak? Is that so?
