{"id":19288335,"url":"https://github.com/techascent/tech.resource","last_synced_at":"2025-04-22T04:33:17.716Z","repository":{"id":57714054,"uuid":"153025893","full_name":"techascent/tech.resource","owner":"techascent","description":"RAII resource management system","archived":false,"fork":false,"pushed_at":"2023-08-27T18:58:25.000Z","size":122,"stargazers_count":31,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-28T13:40:32.046Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Clojure","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/techascent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-14T22:46:11.000Z","updated_at":"2023-09-08T19:43:05.000Z","dependencies_parsed_at":"2023-01-29T17:45:58.771Z","dependency_job_id":null,"html_url":"https://github.com/techascent/tech.resource","commit_stats":null,"previous_names":["tech-ascent/tech.resource"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.resource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.resource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.resource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techascent%2Ftech.resource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techascent","download_url":"https://codeload.github.com/techascent/tech.resource/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223888375,"owners_count":17220083,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T22:08:45.460Z","updated_at":"2024-11-09T22:08:46.068Z","avatar_url":"https://github.com/techascent.png","language":"Clojure","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tech.resource\n\n[![Clojars Project](https://img.shields.io/clojars/v/techascent/tech.resource.svg)](https://clojars.org/techascent/tech.resource)\n\n[API Documentation](https://techascent.github.io/tech.resource/)\n\n\nGeneric thread-safe and exception-safe non-gc or 'off heap' resource management.\n\n\nThere is some more information on our [blog](http://techascent.com/blog/generalized-resource-management.html).\n\n\n\n```clojure\n;;create the file\n(defn new-random-file\n  [fname]\n  (resource/track (RandomAccessFile. fname) #(.close item)))\n\n\n;;Use it\n(resource/stack-resource-context\n  (let [f (new-random-file fname)]\n    ...\n    ))\n\n;;Similar to with-open, this will close the file regardless\n;;of what happens.  The advantage is this can map to anything\n;;you can implement the resource protocol with meaning network sockets,\n;;JNI pointers, GPU contexts, etc.  It is also possible to have the\n;;gc track something if the dispose functionality does not reference\n;;the item itself.\n\n(let [f (resource/track (double-array [1 2 3]) #(println \"disposed\") :gc)]\n  ...)\n;;Disposed will print when the gc determines the double array is no longer\n;;reachable\n```\n\n\nThere are now explicit methods to create either a weak or soft reference.\nFor the differences, see \n[here](https://stackoverflow.com/questions/299659/whats-the-difference-between-softreference-and-weakreference-in-java).\n\n* [gc reference documentation and implementation](https://github.com/techascent/tech.resource/blob/master/src/tech/resource/gc.clj).\n* [stack documentation and implementation](https://github.com/techascent/tech.resource/blob/master/src/tech/resource/stack.clj).\n\n\n### Usage\n\n\nCheckout the [stack](test/tech/resource_test.clj) and \n[gc](test/tech/gc_resource_test.clj) tests.\n\n\n\nOr take a giant leap and check out [tvm-clj](https://github.com/techascent/tvm-clj).\n\n\n\n\nDistributed under the Eclipse Public License either version 1.0 or (at\nyour option) any later version.  Complements of Tech Ascent, LLC.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.resource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechascent%2Ftech.resource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechascent%2Ftech.resource/lists"}