Will stream classes or connections considered as a resource leak in Java

前端 未结 3 1661
野性不改
野性不改 2020-12-06 08:38

Java has no lifetime for an object, this is managed by the garbage collector. And if I use some IO classes without closing it, or some DBConnection

3条回答
  •  失恋的感觉
    2020-12-06 08:57

    "Java has no lifetime for an object, this is managed by the garbage collector." -Not entirely true. It's firstly 'managed' by the way a program is written. If an object is out of scope, GC will most likely take care of it.

    If you don't close br, it will live until the program exits unless collected by GC if ready for collection. It doesn't leak, just a long living variable.

提交回复
热议问题