From: Bruce S. <Bru...@nc...> - 2009-06-28 23:15:29
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> I guess the documentation needs to be more clear, in that it's using the word "delete" too informally. But it is important to note the full statement:<br> <span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: 'Times New Roman'; font-size: 16px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"> <p class="Normal" style="margin: 6pt 0pt 0pt; display: block; text-align: justify; text-indent: 0pt; font-size: 10pt; color: rgb(0, 0, 0); text-decoration: none; vertical-align: baseline; text-transform: none; font-family: sans-serif;">To delete a Visual object just make it invisible:<span class="Apple-converted-space"> </span><span class="attribute" style="color: rgb(255, 0, 0);">ball.visible = 0</span></p> <p class="Normal" style="margin: 6pt 0pt 0pt; display: block; text-align: justify; text-indent: 0pt; font-size: 10pt; color: rgb(0, 0, 0); text-decoration: none; vertical-align: baseline; text-transform: none; font-family: sans-serif;">Technical detail: If you later re-use the name<span class="Apple-converted-space"> </span><span class="attribute" style="color: rgb(255, 0, 0);">ball</span>, for example by creating a new object and naming it <span class="attribute" style="color: rgb(255, 0, 0);">ball</span>, Python will be free to release the memory used by the object formerly named<span class="Apple-converted-space"> </span><span class="attribute" style="color: rgb(255, 0, 0);">ball</span><span class="Apple-converted-space"> </span>(assuming no other names currently refer to that object).</p> </span><br> Probably the first sentence should be replaced by this: "To hide a Visual object just make it invisible: ball.visible = 0. This does not delete the information about the object from the computer's memory, since you can at a later time make it visible again by setting ball.visible = 1."<br> <br> Additional technical point: Python maintains a reference count on objects, with the policy that if the reference count goes to zero the object can be deleted from memory, as there is no longer any way to refer to it. A Visual object has one additional reference count associated with the fact that some human may be looking at the object if it is "visible", which is why you have to make an object invisible (which decrements the reference count) before you can get it fully deleted.<br> <br> Bruce Sherwood<br> <br> Jamie Riotto wrote: <blockquote cite="mid:958...@ma..." type="cite"> <pre wrap="">On Sat, Jun 27, 2009 at 11:38 PM, Guy K. Kloss <a class="moz-txt-link-rfc2396E" href="mailto:g....@ma..."><g....@ma...></a> wrote: </pre> <blockquote type="cite"> <pre wrap="">On Sun, 28 Jun 2009 17:51:47 Jamie Riotto wrote: </pre> <blockquote type="cite"> <pre wrap="">I believe setting scene.visible to false just makes the scene invisible, it doesn't delete it, unlike objects. If you'd like to reinitialize the scene then just delete all visible objects: for obj in scene.objects: obj.visible = false </pre> </blockquote> <pre wrap="">That ought to be "False". But that also doesn't work, as visual.scene is the object that complains about re-initialised, and that one is a module level variable, so it can only be initialised once per running Python process. Iterating over the objects and setting their visibility to False should (A) just hide them, but not delete them, and (B) still leave the current scene's instance in the state it's in. So that's not helpful, either. </pre> </blockquote> <pre wrap=""><!----> Guy, I understand my suggestion didn't fix your problem, but as to your point (A), that setting visiblity to False should hide objects and not delete them, from the VPython Docs: Deleting an Object To delete a Visual object just make it invisible: ball.visible = 0 (Not that I agree with the behavior, I'd prefer being able to make things visible and invisible at will without having to manage the invisible objects (i.e. deleted) myself) Cheers - jamie ------------------------------------------------------------------------------ _______________________________________________ Visualpython-users mailing list <a class="moz-txt-link-abbreviated" href="mailto:Vis...@li...">Vis...@li...</a> <a class="moz-txt-link-freetext" href="https://lists.sourceforge.net/lists/listinfo/visualpython-users">https://lists.sourceforge.net/lists/listinfo/visualpython-users</a> </pre> </blockquote> </body> </html> |