the problem is the number of children is changing each time you remove a child, so you
can remove from the end of the list to the front or remove the first element until the
list is empty.
while (int i = theGroup.numChildren()-1; i >= 0; i--)
theGroup.removeChild(i);
or
while (theGroup.numChildren() > 0)
theGroup.removeChild(0);
Sean
> -----Original Message-----
> From: Lan Wu-Cavener [mailto:[EMAIL PROTECTED]]
> Sent: Monday, March 11, 2002 10:38 AM
> To: [EMAIL PROTECTED]
> Subject: [JAVA3D] dispose the children of a detached BranchGroup
>
>
> Hi, every one:
>
> I have a problem with disposing the contents of a detached Branchgroup
> without setting the BranchGroup to null.
> I have a BranchGroup generated dynamically through the user
> interacting
> with the program. I need to often to detach the BranchGroup
> and would like
> to garbage collect its children. I tried two approaches as follows:
>
> 1.
> int numb =
> theGroup.numChildren();
>
> System.out.println("numb="+numb);
> for (int index=0;
> index<numb-1;
> index++)
>
> theGroup.removeChild(index);
>
> I got the error of "ArrayIndexOutOfBoundry, 19>=19 " although numb=38.
>
> 2.
> Enumeration enu =
> theGroup.getAllChildren();
> while (enu.hasMoreElements())
>
> enu.nextElement().remove();
>
> for this approach, I got required variable, found value for the last
> statement.
>
> My question is how can I dispose the children of a detached
> BranchGroup
> without setting this BranchGroup to null. I need to keep it for re-use
> later.
>
> Thanks in advance for any suggestion.
>
> Lan
>
> Lan Wu-Cavener
> Research Associate and Programmer
> Dept. of Landscape Architecture
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff JAVA3D-INTEREST". For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ==============================================================
> =============
> To unsubscribe, send email to [EMAIL PROTECTED] and
> include in the body
> of the message "signoff JAVA3D-INTEREST". For general help,
> send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
==========================================================================To
unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".