# Dictionary good practice

**URL:** <https://forum.kirupa.com/t/dictionary-good-practice/304836>\
**Category:** flash\
**Created:** [February 15, 2010, 7:48am UTC](https://forum.kirupa.com/t/dictionary-good-practice/304836 "2010-02-15T07:48:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stratboy](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/stratboy/32/3054_2.png) [@Stratboy](https://forum.kirupa.com/u/Stratboy)\
**Post date:** [February 15, 2010, 7:48am UTC](https://forum.kirupa.com/t/dictionary-good-practice/304836/1 "2010-02-15T07:48:30Z")

</div>

Hi! A few questions about dictionary:

1. Is anything wrong in doing something like this:

```auto

var mc = new MovieClip();
dictionary[mc] = mc; //in other words, the same mc as key AND value

```

I mean, any particular implication on performance? is it a bad practice?

1. Does it cause performance or memory problems to use moviclips as keys instead of primitive values?

2. Is is a good practice doing something like this:

```auto
private function prepare(){
   fxArray = new Array();
   fxDictionary = new Dictionary();
}

public function addFxListener(fx){
   fxArray.push(fx);
   fxDictionary[fx] = fxArray.length-1;
fxArray[fxDictionary[fx]].addEventListener(PageEvent.TRANS_IN_FINISHED,notifyPageEvent);
fxArray[fxDictionary[fx]].addEventListener(PageEvent.TRANS_OUT_FINISHED,notifyPageEvent);
}

```

Where fx are classes extending Movieclip, fxArray is an array where I store fx referencies and fxDictionary is a dictionary where I store indexes of the fxArray, using the relative fx as key. What do you think about this kind of usage?

also another question:

1. Does a code like this create a reference to mc (along with events and so on?):

```auto
dictionary[mc] = 7 //(the value is a primitive)

```

I mean, if I then destroy mc, the line above will still keep it somehow alive?

Ooops… Maybe I should move this thread to the AS3 forum??? Could the administrator do it maybe? Sorry…
