1

In this Flambe guide it says:

"This dispose function removes this component from its owning entity. You should override the dispose-function in order to dispose objects yourself, to prevent memory leaks."

I have 3 questions:

  1. How should I override the dispose function?

  2. How to properly use the dispose function?

  3. Is there a way to check for memory leaks in Flambe?

Robert777
  • 801
  • 3
  • 12
  • 24

1 Answers1

1

1 If you're using Component

 override public function dispose() {
   myReferences = null;
   myDisposable.dispose();

   super.dispose();
 }

If you are not using a Component: You can implement Disposable and dispose when needed in another dispose function.

2 You need to clear references to objects, that means set it to null. You need to close signal connections that are created in that context. You need to dispose the Disposables.

3 If you use the JavaScript (html) target, you can use the chrome debug inspector / devtools. You can collect memory profiles, observe the cpu usage etc. Really useful! https://developer.chrome.com/devtools/docs/profiles

Mark Knol
  • 9,663
  • 3
  • 29
  • 44
  • Thanks for your answer. Just a few questions: When you wrote `myReferences` you meant references to this component object, right? What is `myDisposable`? We call `super.dispose()` in order to remove this component from its owner, right? – Robert777 Jul 08 '16 at 21:31
  • 1
    myDisposable is anything used in your component that is implementing `Disposable` interface. myReference was another example for objects used in your component which are not implementing `Disposable`. – Mark Knol Jul 10 '16 at 21:11
  • 1
    And yes, you should always do `super.dispose()`, because this removes the component from its owner. – Mark Knol Jul 10 '16 at 21:12
  • 1
    For convenience you can also use a `Disposer` in your component, add any `Disposable` to it (like signals etc) and do `myDisposer.dispose()` when you override the dispose function. – Mark Knol Jul 10 '16 at 21:17
  • 1
    https://github.com/markknol/flambe-guide/wiki/Signal-Event-System#boom-dispose-signals – Mark Knol Jul 10 '16 at 21:17