Thanks!
I have looked a bit further to understand what is going on. I think one of the major memory use was for the default JoinForm["Round"]
which uses a sphere to render the joints. By using CapForm["Square"]
and JoinForm["Miter"]
the memory usage dropped considerably.
Furthermore, the Graphics Primitives can be generated in two ways:
- where each line/tube is a individual primitive
All lines/tubes are wrapped in one primitive
tt = RandomSample[trc, 250];
cc = MakeColor /@ tt;
(*tubes*)
tt1 = {CapForm["Square"], JoinForm["Miter"],
MapThread[Tube[#1, .5, VertexColors -> #2] &, {tt, cc}, 1]};
tt2 = {CapForm["Square"], JoinForm["Miter"],
Tube[tt, .5, VertexColors -> cc]};
(*lines*)
ll1 = {CapForm["Square"], JoinForm["Miter"],
MapThread[Line[#1, VertexColors -> #2] &, {tt, cc}, 1]};
ll2 = {CapForm["Square"], JoinForm["Miter"],
Line[tt, VertexColors -> cc]};
Whit this it seem that the Tube rendering is much more responsive so I could test the following.
vp = {1.3, -2.4, 2};
va = 15. Degree;
vv = {0, 0, 1};
opts = Sequence[{Method -> {"TubePoints" -> {6, 1}},
Lighting -> light, ImageSize -> 400, SphericalRegion -> True,
ViewPoint -> Dynamic[vp], ViewAngle -> Dynamic[va],
ViewVertical -> Dynamic[vv], Boxed -> False,
Background -> Lighter@Gray,
LabelStyle -> Directive[{Bold, 16, White}]}];
Grid@{{Graphics3D[ll1, opts, PlotLabel -> "Individual"],
Graphics3D[ll2, opts, PlotLabel -> "Group"]},
{Graphics3D[tt1, opts, PlotLabel -> "Individual"],
Graphics3D[tt2, opts, PlotLabel -> "Group"]}}
Which gives this figure
![enter image description here](https://community.wolfram.com//c/portal/getImageAttachment?filename=5531image1.png&userId=1332602)
However, as is indicated by the Black arrows, the coloring of the grouped primitives sometimes fails, while the individual primitives don't.
The memory usages is reduced considerably but still increases with rotation.
![enter image description here](https://community.wolfram.com//c/portal/getImageAttachment?filename=mem.png&userId=1332602)
And as the only figure that does this is the Tubes with individual primitives. Once I delete that figure from the grid the memory drops to the starting memory. With that figure removed, I can do whatever I want without increasing memory usage.
![enter image description here](https://community.wolfram.com//c/portal/getImageAttachment?filename=9735image2.png&userId=1332602)
![enter image description here](https://community.wolfram.com//c/portal/getImageAttachment?filename=1151mem2.png&userId=1332602)
So for now if I want to render the colors correctly I should use the individual primitives but with memory leaks after rotation. But if I want to rotate I use the grouped primitives and accept the wrong coloring.
So the workaround I have now is to manipulate the images using lines and switching to the tube render once I'm happy with the view.
Manipulate[
{Graphics3D[ll2, opts], Graphics3D[tt1, opts]}[[n]]
, {n, {1 -> "Lines", 2 -> "Tubes"}}]
Each time I switch back to lines the memory is cleared.