Not want to clone specific fields on controls when calling spatial.clone()?

Hi friends

When calling clone() method on spatial it also clones it’s controls. In the case of cloning controls, it calls jmeClone() from AbstractControl. And this clones all fields to new control.
My question is, is there any way to indicate to cloner not to clone some specific fields of control but instead reference them ?
I hope my question is clear enough.

Is this one of your controls? Implement your own clone method.

Yes

I know I can override

@Override     
public Object jmeClone() {
                CustomeLodControl clone = (CustomeLodControl)super.jmeClone();
               //do my stuffs 
                return clone;
            }     

But … You know … the problem here is when I am calling super.jmeClone();
it clones all fields already. And in one of my fields i have an array with huge amounts of data in it which I never want to clone it (which takes space in memory). So I want to prevent cloning it at first hand .

PS: Note that I am calling clone() method on spatial and it internally calls this jmeClone() method, so I can not write other clone method for my control, but override jmeClone() .

The default clone is only doing a shallow clone.

It’s cloneFields() that deep clones anything and you can control that in your own cloneFields() method by not cloning but pushing the cached reference into the cloner before calling suprt.cloneFields() (if you need to).

Edit: and actually, nothing is deep cloned unless you deep clone it. So just don’t.

1 Like

Ah…Yes. Thanks a lot for explanation. :grinning: