# In-Memory File: Close & Reset

**URL:** <https://clarionhub.com/t/in-memory-file-close-reset/7590>\
**Category:** questions\
**Tags:** drivers\
**Created:** [October 21, 2024, 11:40pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590 "2024-10-21T23:40:06Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [October 21, 2024, 11:40pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/1 "2024-10-21T23:40:06Z")

</div>

I long ago made notation to ALWAYS call Reset(Force) for an In-Memory file AFTER the file was Closed. From where this "requirement" originated, I no longer remember and I can't find any further documentation.

Because I am now seeing some GPFs after procedures where In-Memory tables are used, I am beginning to question the practice. Any ideas or history?

---

<div class="post-metadata">

**Author:** ![vitesse](https://clarionhub.com/user_avatar/clarionhub.com/vitesse/32/837_2.png) [@vitesse](https://clarionhub.com/u/vitesse)\
**Post date:** [October 22, 2024, 1:58am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/2 "2024-10-22T01:58:10Z")

</div>

Hi Douglas

see this thread:

> [@A quicker way of deleting In-Memory table?](https://clarionhub.com/t/a-quicker-way-of-deleting-in-memory-table/5407):
>
> I have a standard in-memory table (defined in DCT) and a standard ABC Browse box on it. When I load a window I load data manually to it and it works. But I need to load different data depending on settings from the same window - so I need to re-load my table. and so I need to empty/delete the table somehow quickly. the standard loop takes awhile clear(pre:record) set(table) LOOP NEXT(table) IF ERRORCODE() THEN BREAK. DELETE(table) . so is t…

I am not sure why you need to empty the file after it is closed - perhaps to free up memory?

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [October 22, 2024, 2:28am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/3 "2024-10-22T02:28:16Z")

</div>

> [@vitesse](#):
>
> I am not sure why you need to empty the file after it is closed - perhaps to free up memory?

I assume yes, but scratching my head wondering why my notes & habits have specifically said after.

---

<div class="post-metadata">

**Author:** ![Jane](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/ecb155/32.png) [@Jane](https://clarionhub.com/u/Jane)\
**Post date:** [October 22, 2024, 3:24am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/4 "2024-10-22T03:24:16Z")

</div>

No idea, which doesn’t preclude a WAG based on a quick search of the docs.

It looks as if the reset(ForceReset) tries to open with deny-all. So the file should presumably be closed before calling.

Now, as to why you’re calling it…

 ![imddForce](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/f/f887f86f14a9638b284a2a0e6c9a8e8a74d8a887.png)

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [October 22, 2024, 5:10am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/5 "2024-10-22T05:10:32Z")

</div>

To be clear Douglas, you are calling RESET on an _object_ and not on the file itself?

I expect your habit originated with the idea that “the memory table is a temp store, so when i close it i want to empty it.”

That is likely true for some use cases, and not true for others. If your mem table does NOT have /THREADEDCONTENT then it is shared across multiple threads. Emptying the table for everyone just because 1 thread is done seems like a bug.

So in your case I guess, context will matter, but if you do this i recommend you make sure the file is set to have /THREADEDCONTENT.

---

<div class="post-metadata">

**Author:** ![Bruce](https://clarionhub.com/letter_avatar_proxy/v4/letter/b/ccd318/32.png) [@Bruce](https://clarionhub.com/u/Bruce)\
**Post date:** [October 22, 2024, 5:15am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/6 "2024-10-22T05:15:46Z")

</div>

To be clear Douglas, you are calling RESET on an _object_ and not on the file itself?

I expect your habit originated with the idea that “the memory table is a temp store, so when i close it i want to empty it.”

That is likely true for some use cases, and not true for others. If your mem table does NOT have /THREADEDCONTENT then it is shared across multiple threads. Emptying the table for everyone just because 1 thread is done seems like a bug.

So in your case I guess, context will matter, but if you do this i recommend you make sure the file is set to have /THREADEDCONTENT.

---

<div class="post-metadata">

**Author:** ![totalhip](https://clarionhub.com/user_avatar/clarionhub.com/totalhip/32/1477_2.png) [@totalhip](https://clarionhub.com/u/totalhip)\
**Post date:** [October 22, 2024, 12:14pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/7 "2024-10-22T12:14:55Z")

</div>

Yes, always THREADEDCONTENT.

> [@Bruce](#):
>
> I expect your habit originated with the idea that “the memory table is a temp store, so when i close it i want to empty it.”

I agree, most likely the idea. However, I can’t take credit for such deep thinking. It’s one of those bits I picked up from docs or a respected someone for work I was doing during COVID lock down.

---

<div class="post-metadata">

**Author:** ![Dirk1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@Dirk1](https://clarionhub.com/u/Dirk1)\
**Post date:** [October 22, 2024, 4:20pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/8 "2024-10-22T16:20:46Z")

</div>

I use before the file is closed

```
  empty(IMFILE)!empty() needs file to have exclusive use otherwise it will fail 
  if errorcode() or records(IMFILE) > 0 
    Set(IMFILE)
    loop until Access:IMFILE.Next()
        Access:IMFILE.DeleteRecord(0)
    end
  end

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 23, 2024, 3:36am UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/9 "2024-10-23T03:36:24Z")

</div>

> [@Dirk1](#):
>
> I use before the file is closed
> 
> ```auto
> Empty(IMFILE) ... LOOP ... DELETE
> 
> ```

To be absolutely sure the file was empty, when it was very important, I would Loop and Delete 9 Times. I guess my concern was a flaw in the driver with DELETE might cause sequential processing NEXT to skip a record.

I never saw this, but its just 2 extra lines of code, and the extra LOOP only happens “While Records \> 0” so … never … if the driver next works. E.g.

```clarion
 LOOP 9 TIMES ! 9 TIMES prevents infinite loop should Delete fail to work
    Set(IMFILE)
    loop until Access:IMFILE.Next()
       Access:IMFILE.DeleteRecord(0)
    end
 WHILE Records(IMFILE) > 0 ! All were not deleted, so loop and delete again ... driver bug

```

With the added complexity of ABC doing the Delete inside its function it may not work, so this gives up after 9 tries.

---

<div class="post-metadata">

**Author:** ![jslarve](https://clarionhub.com/letter_avatar_proxy/v4/letter/j/e480ec/32.png) [@jslarve](https://clarionhub.com/u/jslarve)\
**Post date:** [October 23, 2024, 7:38pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/10 "2024-10-23T19:38:31Z")

</div>

That’s why I looped backwards in this post [A quicker way of deleting In-Memory table? - #4 by jslarve](https://clarionhub.com/t/a-quicker-way-of-deleting-in-memory-table/5407/4)

---

<div class="post-metadata">

**Author:** ![Dirk1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@Dirk1](https://clarionhub.com/u/Dirk1)\
**Post date:** [October 28, 2024, 6:06pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/11 "2024-10-28T18:06:42Z")

</div>

So is this a good approach?

```clarion
if records(IMFILE) > 0 
    Set(IMFILE)
    loop until Access:IMFILE.Previous()
        Access:IMFILE.DeleteRecord(0)
    end
 end

```

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [October 28, 2024, 6:53pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/12 "2024-10-28T18:53:21Z")

</div>

> [@jslarve](#):
>
> That’s why I looped backwards in this post

I don’t know what Jeff is referring to. In the Link he posted there is no example or explanation that I see? Just the same statement.

> [@Dirk1](#):
>
> ```auto
> Set(IMFILE)
> loop until Access:IMFILE.Previous()
> Access:IMFILE.DeleteRecord(0)
> end
> 
> ```

If I had to guess… you think that Previous() will keep starting from the Last Record in the File?

IMO the [Help](https://clarion.help/doku.php?id=previous_read_previous_view_record_in_sequence_.htm) says not, the 2nd … Nth PREVIOUS will move back one record. That is how I understand Sequential processing in Clarion to work, and I write code with that assumption.

> The first PREVIOUS following a SET reads the record at the position specified by the SET statement.

> Subsequent PREVIOUS statements read subsequent records in reverse sequence. The sequence is not affected by any GET, REGET, ADD, PUT, or DELETE.

The way I could see it working is if the SET was repeated:

```clarion
  LOOP 
     SET(Key)
     PREVIOUS(Key) !move to Last Record
     IF ErrorCode() THEN BREAK.
     DELETE(File)
!? IF ERRORCODE() THEN BREAK.   
  END

```

I would not write that code without a LOOP limit like `LOOP 2*Records(File)` in case a record could not delete, maybe because it was LOCKed. That is very unlikely as LOCK is rarely used. The File could be STREAM which locks it and prevents all deletes. In that case my original LOOP 9 TIMES at least gives up and does not hang.

This whole drift I started with multiple tries of Delete is kind of academic. I have never seen it happen and the docs say DELETE does not affect Next or Previous. But as I said “with 2 lines of code (Loop Times + While Records\>0) you can be sure”.

---

<div class="post-metadata">

**Author:** ![Dirk1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@Dirk1](https://clarionhub.com/u/Dirk1)\
**Post date:** [October 29, 2024, 5:14pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/13 "2024-10-29T17:14:46Z")

</div>

Okay Carl, thanks.  
Looping backwards doesn’t seem to make any difference if previous is ment

---

<div class="post-metadata">

**Author:** ![Dirk1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@Dirk1](https://clarionhub.com/u/Dirk1)\
**Post date:** [October 29, 2024, 5:39pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/14 "2024-10-29T17:39:05Z")

</div>

i found this:

when looping through a table to delete specific selected records, go backwards.

The reason is, that, when the one record is deleted and the loop skips forward,  
it starts from the deleted one, which no longer exists, so it actually takes  
the next existing. Which is then not processed, because the table has shrunk  
for one record.

so try looping backwards by -1.

---

<div class="post-metadata">

**Author:** ![Dirk1](https://clarionhub.com/letter_avatar_proxy/v4/letter/d/977dab/32.png) [@Dirk1](https://clarionhub.com/u/Dirk1)\
**Post date:** [October 31, 2024, 12:33pm UTC](https://clarionhub.com/t/in-memory-file-close-reset/7590/15 "2024-10-31T12:33:06Z")

</div>

I changed my code to:

LOOP Access:IMFILE.GetOpened() TIMES  
Access:IMFILE.Close()  
END  
remove(IMFILE)  
create(IMFILE)
