简体   繁体   中英

How to cleanup an ETS table after use?

I am creating an ETS table with an unique atom name within a process. The process executes and terminates. Will the process termination clear the ETS consumed resources (memory) ?

Is it necessary to cleanup/delete an ETS table after using ?

This is what I am doing:

parentProcess() -> 
     UniqueAtomTerm = 'myAtomIdentifier',
     ets:new( UniqueAtomTerm, [] ),
     myProc (UniqueAtomTerm).

.

myProc( UniqueAtomTerm ) ->
    .... do some inserts, etc
    ets:delete_all_objects( UniqueAtomTerm ).

It appears that if I try to create another ETS table with the same atom identifier, it will error, therfore the above does not appear to work. Per the above, I cannot make the ETS table options as private as I need to insert from a different process (just in case private would clear the ETS resources ).

So the bottom line question: How to remove all resources from a specific ETS table ?

The process which created a table is the tables's owner. If the owner terminates the table is deleted and all its resources are deleted too. You can change owner by calling ets:give_away/3 . Also you can delete tables explicitly with ets:delete/1 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM