Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
adrianc1982
Visitor

Scene Graph Destroying nodes and childs?

So my application is a little complex and I havent found out how to kill or destroy a node or a child.

Could anyone provide an example of how to HANDLE for example the back key to destroy a child and the nodes used inside it?

Im sorry maybe im not getting correctly how to handle scenegraph as a whole.
0 Kudos
6 REPLIES 6
Veeta
Visitor

Re: Scene Graph Destroying nodes and childs?

You call m.top.removeChild() to remove it.  So long as there are no references left, it will be garbage collected.

You can do this within 'onKeyEvent()' in the parent node to handle the "back" keypress.
0 Kudos
adrianc1982
Visitor

Re: Scene Graph Destroying nodes and childs?

"Veeta" wrote:
You call m.top.removeChild() to remove it.  So long as there are no references left, it will be garbage collected.

You can do this within 'onKeyEvent()' in the parent node to handle the "back" keypress.

you are very kind for answering as fast as you did. Could i abuse a little longer and ask for a very simple example, i know how to handle the back on the parent but could you code a little example just to see how you use it.
From the documentation i see removeChild requieres a parameter, you didnt use it in your example.
0 Kudos
adrianc1982
Visitor

Re: Scene Graph Destroying nodes and childs?

Veeta thank you so much i found my answer in the docs, sorry im just new to scene graph and i oversaw some stuff in the tutorial and references guide

heres the answer if anyones looking for it.

https://sdkdocs.roku.com/display/sdkdoc ... OldScreens

a complete example on how to use removeChild.

You do have to call m.top.removeChild plus the object that points to the child

m.top.removeChild(m.settingScreen) ' thats just an example  😄
0 Kudos
adrianc1982
Visitor

Re: Scene Graph Destroying nodes and childs?

A related question, i killed succesfully the child my settings menu

BUT i used some render nodes like rectablgles, labels and other, those nodes I see them after i call the back and kill the parent but the nodes i see are still there with the getAll() command.

Do those nodes get garbage collected? I will not call them as the parent has already been killed i dont have access to them that is until i call the create child again and have access to them via m.top.findNode("")

Sorry scene graph seems a little harder than pure brightscript and roImageCanvas, sure its a lot easier to draw stuff on screen but you have to deal with xml, interfaces, nodes, parents and childs hahahah
0 Kudos
EnTerr
Roku Guru

Re: Scene Graph Destroying nodes and childs?

Just to be clear, you don't remove with `m.top.removeChild()` but by calling .removeChild() on the parent node.
I.e. in the general case that is parentNodeObject.removeChild(childNodeObject)

In the special case where the noid was added as child to a custom component (often a Scene), where the current script is running - then yes, the parent is `m.top` and the special-case incantation is m.top.removeChild(noid) indeed. But if you were trying to remove child of a child of a scene, "m.top" won't do.

Regarding if the removeChild()-ed node gets de-allocated, did you make sure there are no more variables pointing to it? Sometimes you'll have to do things like `myChildNode = invalid` right after calling .removeChild(myChildNode) to severe the last remaining link.

Regarding the if the children of removed child get garbage-collected... well, generally speaking they should be - or at least that was the case in SDK1 - but i won't put it past RSG screwing the pooch here. See https://sdkdocs.roku.com/display/sdkdoc ... plications which is beating around the Bushes regarding node-cycles - and for the life of me i cannot tell if forced garbage collection can get rid of these before channel terminates or not?
0 Kudos
adrianc1982
Visitor

Re: Scene Graph Destroying nodes and childs?

"EnTerr" wrote:
Regarding if the removeChild()-ed node gets de-allocated, did you make sure there are no more variables pointing to it? Sometimes you'll have to do things like `myChildNode = invalid` right after calling .removeChild(myChildNode) to severe the last remaining link.

how insightful, I saw this on one of the sample apps for scene graph and didnt understand as to why set it to invalid, now it makes perfect sense, even though the child object doesnt exits anymore the pointer to where that object was created still remains.
0 Kudos