Fork me on GitHub

what happens to unclaimed future results? If I spawn a future and abandon it (say the future stores its result somewhere), and the future creator never derefs the future, what happens to the result? Does it just consume memory in the JVM forever more? Is it gabage collected somehow when the creator returns without the future?


It will be available for garbage collection:

> (future
      (finalize [_]
        (println "goodbye"))))
> (System/gc)


Thankyou. Great little bit of example code.


does this actually garbage collect though?


user=> (def fut
  #_=> (future
  #_=>     (reify
  #_=>       Object
  #_=>       (finalize [_]
  #_=>         (println "goodbye")))))
user=> fut
#object[clojure.core$future_call$reify__8439 0x68d96261 {:status :ready, :val #object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]}]
user=> (System/gc)
user=> fut
#object[clojure.core$future_call$reify__8439 0x68d96261 {:status :ready, :val #object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]}]
user=> @fut
#object[user$fn$reify__2006 0x35c59975 "user$fn$reify__2006@35c59975"]


or will it gc when fut is gced?


will fut be gced when finished?


It will be available for garbage collection when there aren't any references pointing towards it


yep great thanks


but printing “goodbye” means something have been gc’d right when fut was live? i see an other “goodbye” after

(def fut nil)


(def fut
      (finalize [this]
        (println (.hashCode this))))))
=> #'finaliz/fut
=> nil
(.hashCode @fut)
=> 822250702
(def fut nil)
=> #'finaliz/fut
=> nil



Nom Nom Mousse06:08:20

To keep two maps in sync I guess the easiest thing to do is to create an atom with two fields that contain the maps like :state->jobids and :jobid->state, right? And then ensure that all operations keep them in sync

Nom Nom Mousse06:08:32

Let's say I have an atom like above with

{:jobid->state {:jobid1 :ready :jobid2 :in-progress ...}
 :state->jobids {:ready #sorted-set{:jobid3 ...}}
                 :in-progress #sorted-set{:jobid4...}
                 :done #sorted-set{:jobid5 ...}}
Is there any advantage in making it a defrecord? Or is that only advantageous if I want polymorphism? I do Scala at work so there I'd make it an object. But I guess there is no advantage to it here. I could just have it in a namespace with the getter/setter/lookup-functions.


I don’t really see any benefit in turning this into a record. You already have it properly structured with nice names and all that and Clojure’s APIs work best with this kind of data 🙂 If you need Java interop then maybe, but as is, nah.

Nom Nom Mousse08:08:27

That is what I thought. Thanks! 🙏

Marco Schneider08:08:39

Hey everyone. I’ve got a seemingly very basic question: I want to attach a Thread$UncaughtExceptionHandler to the current thread (my main thread). I do this via

(ns exception-test.core)

(defn -main
  [& args]
   (reify Thread$UncaughtExceptionHandler
               (^void uncaughtException
                [^Thread$UncaughtExceptionHandler this ^Thread t ^Throwable e] ; -> void
                (println "caught:" (.getMessage e)))))
  (throw (Exception. "this is the ex"))
  (println "after ex"))

Marco Schneider08:08:06

My expectation would be that the "this is the ex" expection is caught, but it isn’t. Maybe someone can help me out here?


are you testing your main function in REPL?

Marco Schneider08:08:31

No, I’m calling it from the shell via clojure -M -m exception-test.core


ok, that isn’t working because of exception thrown by your code will be catched by clojure’s main function

Marco Schneider09:08:41

Thanks a lot. I just figured out the same thing.


Hi, Clojurians. I’m Younghwan Nam. I’d love to ask about AWS lambda layer where I am stuck in. in deps.edn , I’d like to know how to add sth like scope : provided . I’m considering Lambda Layer to separate dependencies. after making layer, I was trying to make uberjar to deploy lambda. but because of aot: true dependencies are necessary. I have no idea how to deal with it. Thanks a lot.


Here is my dep.edn for application.

{:paths ["src" "resources"]
 :deps {org.clojure/clojure {:mvn/version "1.10.3"}
        com.amazonaws/aws-lambda-java-core   {:mvn/version "1.0.0"}
        com.amazonaws/aws-lambda-java-events {:mvn/version "1.0.0"}}
 {:dev  {:extra-deps { {:mvn/version "0.3.2"}}}
  :uberjar {:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.0.211"}}
            :exec-fn hf.depstar/uberjar
            :exec-args {:aot true
                        :jar "lambda-demo.jar"
                        :main-class "yhnam.lambda-demo"
                        :sync-pom true}}}}


Test for separate java-time dependency


I'd say that scope provided is something for libs to use, not applications If you need to make a dependency optional, you can simply isolate it via the :aliases mechanism e.g. it can be present under the :dev alias but otherwise absent by default. Anyway I'd recommend taking a step back and describing your problem more precisely, before considering any specific solution


So basically you want to compile your AOT code with some dependency on the classpath and then make an uberjar with that dependency not on the classpath


or otherwise not included in the uberjar


depstar supports different sets of aliases for compilation and for JAR-building, which was added specifically for this use case.


:aliases and :compile-aliases are the exec arguments you need but you'll need to ensure that what you need for compilation is added via an alias, so that you can tell depstar "compile it with these dependencies" and then "build it with these different dependencies".

❤️ 4
kwladyka19:08:31 here is example of real code for compile to uberjar and publish to clojars consider just use . I didn’t have a chance to try, but looks like it can be new standard.


@U0WL6FA77 That is not a useful example: it does not involve :aliases or :compile-aliases for depstar which is what the OP needs.


ok sorry, I didn’t quite understand the question.


Thanks a lot! it’s really helpful.


confirmed, it was the issue


it is worth to look on number of threads in the process. if it is growing in time it can means something not close properly.


It is impossible to defrecord with the same name as a class in java.lang, right? E.g. (defrecord Enum []) fails with Enum already refers to: class java.lang.Enum.


This seems to work:

(ns-unmap *ns* 'Enum)
(defrecord Enum [])


not sure if there's a cleaner way

Alex Miller (Clojure team)22:08:29

Seems like the best idea I can think of