[ https://issues.apache.org/jira/browse/CURATOR-477?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16625163#comment-16625163 ]
ASF GitHub Bot commented on CURATOR-477: ---------------------------------------- Github user dragonsinth commented on a diff in the pull request: https://github.com/apache/curator/pull/278#discussion_r219703563 --- Diff: curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/TreeCache.java --- @@ -263,15 +284,31 @@ private void doRefreshData() throws Exception { if ( dataIsCompressed ) { - client.getData().decompressed().usingWatcher(this).inBackground(this).forPath(path); + maybeWatch(client.getData().decompressed()).forPath(path); } else { - client.getData().usingWatcher(this).inBackground(this).forPath(path); + maybeWatch(client.getData()).forPath(path); } } } + private ErrorListenerPathable<byte[]> maybeWatch(GetDataWatchBackgroundStatable dataBuilder) { + if (disableZkWatches) { + return dataBuilder.inBackground(this); + } else { + return dataBuilder.usingWatcher(this).inBackground(this); + } + } + + private ErrorListenerPathable<byte[]> maybeWatch(GetDataBuilder dataBuilder) { + if (disableZkWatches) { + return dataBuilder.inBackground(this); + } else { + return dataBuilder.usingWatcher(this).inBackground(this); + } + } + --- End diff -- ```java private void doRefreshChildren() throws Exception { if ( treeState.get() == TreeState.STARTED ) { maybeWatch(client.getChildren()).forPath(path); } } private void doRefreshData() throws Exception { if ( treeState.get() == TreeState.STARTED ) { if ( dataIsCompressed ) { maybeWatch(client.getData().decompressed()).forPath(path); } else { maybeWatch(client.getData()).forPath(path); } } } private <T, P extends Watchable<BackgroundPathable<T>> & BackgroundPathable<T>> Pathable<T> maybeWatch(P dataBuilder) { if ( disableZkWatches ) { return dataBuilder.inBackground(this); } else { return dataBuilder.usingWatcher(this).inBackground(this); } } ``` > Ability to turn off Zk Watches in Curator Framework > --------------------------------------------------- > > Key: CURATOR-477 > URL: https://issues.apache.org/jira/browse/CURATOR-477 > Project: Apache Curator > Issue Type: Improvement > Components: Framework > Affects Versions: 4.0.1 > Reporter: Rama Chavali > Priority: Major > > In our use case, we use *{{TreeCache}}* to get Zk Data periodically. We start > *{{TreeCache}}* read data and close it. In this use case, The > {{ZkWatchManager}} of {{ZooKeeper}} class keeps growing for every TreeCache > operation because new {{TreeNode}} objects are created and added there > leading to a memory leak. Also since we do not want the Watcher to > periodically watch, this creates unnecessary background operations. > Can we introduce a builder flag in CuratorFramework's Builder some thing > called "createZkWatches" that we can use to turn the watchers off? The > default would be set to true to retain the current behaviour. > -- This message was sent by Atlassian JIRA (v7.6.3#76005)