# Memory error when for-loop contains too many videos (python, psychopy function visual.MovieStim3)

**URL:** <https://discourse.psychopy.org/t/memory-error-when-for-loop-contains-too-many-videos-python-psychopy-function-visual-moviestim3/8610>\
**Category:** Coding\
**Created:** [July 23, 2019, 3:16pm UTC](https://discourse.psychopy.org/t/memory-error-when-for-loop-contains-too-many-videos-python-psychopy-function-visual-moviestim3/8610 "2019-07-23T15:16:13Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![frank.papenmeier](https://avatars.discourse-cdn.com/v4/letter/f/ec9cab/32.png) [@frank.papenmeier](https://discourse.psychopy.org/u/frank.papenmeier)\
**Post date:** [July 24, 2019, 3:16pm UTC](https://discourse.psychopy.org/t/memory-error-when-for-loop-contains-too-many-videos-python-psychopy-function-visual-moviestim3/8610/3 "2019-07-24T15:16:07Z")

</div>

Open the task manager and check whether a new video instance is added to the python.exe once you load the next video. If so, this would indicate that you are not yet successful in unloading the video.

Also check my answer in the following thread for unloading the movie. In particular, also add the ‘del video.\_mov.reader’ command to your script before the ‘del video.\_mov’ line:

> [@MemoryError or Too many open files with MovieStim3](https://discourse.psychopy.org/t/memoryerror-or-too-many-open-files-with-moviestim3/6513/3):
>
> Hi @carlos, I also encountered the “too many open files” bug with MovieStim3 lately. After digging through the source, I used the following hack to ensure that my movie stimuli were deleted from memory after use. After playing a movie, I call the following on my MovieStim3 object, called “encode” in my case: del encode.\_mov.reader del encode.\_mov encode.\_unload() Maybe this also helps in your situation? All the best, Frank.

---

_[View the full topic](https://discourse.psychopy.org/t/memory-error-when-for-loop-contains-too-many-videos-python-psychopy-function-visual-moviestim3/8610)._
