# Questions about foreign frames

**URL:** <https://swi-prolog.discourse.group/t/questions-about-foreign-frames/5034>\
**Category:** Help!\
**Tags:** ffi\
**Created:** [February 18, 2022, 10:25pm UTC](https://swi-prolog.discourse.group/t/questions-about-foreign-frames/5034 "2022-02-18T22:25:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![john](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/john/32/4162_2.png) [@john](https://swi-prolog.discourse.group/u/john)\
**Post date:** [February 18, 2022, 10:25pm UTC](https://swi-prolog.discourse.group/t/questions-about-foreign-frames/5034/1 "2022-02-18T22:25:21Z")

</div>

Hi!

I have been using SWI-Prolog for the backend of a Win32 GUI application in C with great success, but I am still a little unsure whether I have understood how data should be properly discarded. More precisely, my question is when to use PL\_open/close/discard\_foreign\_frame.

As I understand it, PL\_open\_query creates a query + other data. The query is discarded by PL\_cut/close\_query, but the data is destroyed only by PL\_close\_query and not by PL\_cut\_query.

Am I correct in assuming that PL\_open\_foreign\_frame and PL\_close\_foreign\_frame are not needed around PL\_open+close\_query, but _should_ be used around PL\_open+cut\_query?

Secondly, I am unsure as to which of PL\_close\_foreign\_frame and PL\_discard\_foreign\_frame is preferable, generally. Up until now, I’ve added PL\_open+discard\_foreign\_frame around any interaction with Prolog from C.

I’d be very grateful for any clarifications!
