@@ -706,6 +706,10 @@ open class Terminal {
706706 setup ( )
707707 }
708708
709+ deinit {
710+ TinyAtom . release ( codes: payloadCodes)
711+ }
712+
709713 /// Installs the new colors as the default colors and recomputes the
710714 /// current and ansi palette. This will not change the UI layer, for that it is better
711715 /// to call the `installColors` method on `TerminalView`, which will
@@ -1759,7 +1763,8 @@ open class Terminal {
17591763 }
17601764
17611765 var hyperLinkTracking : ( start: Position , payload: String ) ? = nil
1762-
1766+ private var payloadCodes = Set < UInt16 > ( )
1767+
17631768 func oscHyperlink ( _ data: ArraySlice < UInt8 > )
17641769 {
17651770 let buffer = self . buffer
@@ -1768,6 +1773,7 @@ open class Terminal {
17681773 if let hlt = hyperLinkTracking {
17691774 let str = hlt. payload
17701775 if let urlToken = TinyAtom . lookup ( value: str) {
1776+ payloadCodes. insert ( urlToken. code)
17711777 //print ("Setting the text from \(hlt.start) to \(buffer.x) on line \(buffer.y+buffer.yBase) to \(str)")
17721778
17731779 // Between the time the flag was set, and now `y` might have changed negatively,
@@ -5120,8 +5126,7 @@ open class Terminal {
51205126 * available by scrolling.
51215127 */
51225128 public func garbageCollectPayload( ) {
5123- // stop right away if there is nothing to collect
5124- if TinyAtom . lastCollected == TinyAtom . lastUsed {
5129+ if payloadCodes. isEmpty {
51255130 return
51265131 }
51275132
@@ -5141,16 +5146,10 @@ open class Terminal {
51415146 }
51425147 }
51435148
5144- // since we create atoms in order we expect them to run out of use
5145- // in order as well and stop with first atom that is still in use
5146- for code in UInt16 ( TinyAtom . lastCollected + 1 ) ... UInt16 ( TinyAtom . lastUsed) {
5147- if used. contains ( code) {
5148- // code still in use
5149- break
5150- }
5151-
5152- TinyAtom . lastCollected = Int ( code)
5153- TinyAtom . release ( code: code)
5149+ let released = payloadCodes. subtracting ( used)
5150+ if !released. isEmpty {
5151+ TinyAtom . release ( codes: released)
5152+ payloadCodes. subtract ( released)
51545153 }
51555154 }
51565155
0 commit comments