Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swiz teardown sets up prototype beans that have event handlers #36

Open
bclinkinbeard opened this issue Dec 19, 2011 · 4 comments
Open

Comments

@bclinkinbeard
Copy link
Contributor

Migrated from SWIZ-66

When calling swiz.teardown(), prototype beans that have event handlers get constructed. Attached is a sample application to demonstrate the problem.

It's happening in EventHandlerProcessor.as on line 114. When trying to remove event handlers, it calls bean.source which has a getter with logic to setup the bean if it is not set up yet.

From @brian428

While I don't believe you should be calling teardown() directly, it does look like this would affect most of the processors. Possible fix in BeanFactory:

public function removeBean( bean:Bean ):void
{
    if( beans.indexOf( bean ) > -1 )
        beans.splice( beans.indexOf( bean ), 1 );

    if( !( bean is Prototype ) || Prototype( bean ).initialized )
        tearDownBean( bean );

    bean.beanFactory = null;
    bean.typeDescriptor = null;
    bean.source = null;
    bean = null;
}

Jeffrey Barrus added a comment - 14/Nov/11 4:54 PM
I found the problem because I am trying to do some integration testing and I really need to teardown everything between tests. I know the AutowiredTestCase uses a swiz instance as the event dispatcher rather than the top level application but I have created a FlexUnit Rule instead of using the AutowiredTestCase and I am using the top level application as the dispatcher. Is there a better way for me to tear down everything? When does swiz.teardown() get called normally?

@enter801
Copy link

There is a pull request that fixes this issue, why hasn't this been pulled yet? It's over 4 months old at this point.

@joaofernandes
Copy link

Could this pull request be integrated to the project?

@brian428
Copy link
Member

Hey Joao, I'm afraid it would be something Ben or Chris would have to do.
If you want you can try emailing them to see if they could pull it.

On Wed, Apr 18, 2012 at 9:51 AM, joaofernandes <
[email protected]

wrote:

Could this pull request be integrated to the project?


Reply to this email directly or view it on GitHub:
#36 (comment)

@azack
Copy link

azack commented Jun 15, 2012

I also ran into this with Prototypes that have [Inject] tags in a project using Modules (where the Module Swiz teardowns are quite common, since we load and unload the modules frequently).

It looks to me like this line causes the problem:
https://github.com/swiz/swiz-framework/blob/develop/src/org/swizframework/core/BeanFactory.as#L383

as the .source accessor calls getObject() which causes the Prototype to be instantiated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants