Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm attempting to display an image sequence of 40 images inside of a Manipulate that cycles through each frame with a slider. I would like the Manipulate to appear in a separate DialogBox. I see a significant performance difference if I try to encapsulate this functionality inside its own function. This code displays the dialog nearly instantaneously:

    imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]

However the code below takes around 10 seconds for the dialog to appear:

showit[imageSequence_] := 
      imageSequence[[frame]], {frame, 1, Length[imageSequence], 1}]]


It does not seem to matter if the function definition is surrounded by DynamicModule or not. Any ideas what is going on and what I can do to improve performance while maintaining encapsulation?


share|improve this question
up vote 4 down vote accepted


showit[imageSequence_] := 
    Module[{i = imageSequence}, 
    Manipulate[i[[frame]], {frame, 1, Length[imageSequence], 1}]] ];

As to any insights what is going on here, I think you used the literal imagelist as Manipulate expression, thereby loading the whole of it into the front end and putting it into the manipulate cell. I used i$xxxx as nanipulate expression, which is just a link to the actual imagelist in the kernel, from which a single frame is loaded on demand. Note, that your version of the dialog is self-contained and may be saved and then reopened in another session, my version in that case will not work, since the image list is no longer there in the kernel. Also note, that using DynamicModule doesn't help because it also keeps its variables in the front end. You may also link directly to your image lists in the kernel just by adding SetAttributes[showit, HoldAll] to your code, or using showit[Unevaluated@imageSequence]

share|improve this answer
It works! Any insight as to what exactly is going on behind the scenes? – bridges2 Jul 21 '13 at 19:08
@bridges2, added some to the answer – panda-34 Jul 22 '13 at 5:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.