最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - How to clean groups from produced by GroupBy - Stack Overflow

programmeradmin7浏览0评论

I made following observable, that filters only changes for given ResourceId:

var valueChangesObs = events
  .GroupBy(e => e.ResourceId)
  .SelectMany(e => e.DistinctUntilChanged(e => e.ResouceValue))

However, the there will be too many groups overtime and I need to clean them.

I have another observable, that emits value, when ResourceId becomes deprecated and can be removed.

How to remove specific groups produced by GroupBy over time to avoid memory leak?

I'm have something TakeUntil in mind:

var valueChangesObs = events
  .GroupBy(x => x.ResourceId)
  .TakeUntil(group => g)) 
  .SelectMany(group => group
        .DistinctUntilChanged(x => x.ResouceValue)
        .TakeUntil(x => resourceDeprecatedObservable.First(y => y.ResourceId = x.ResourceId))); 

I made following observable, that filters only changes for given ResourceId:

var valueChangesObs = events
  .GroupBy(e => e.ResourceId)
  .SelectMany(e => e.DistinctUntilChanged(e => e.ResouceValue))

However, the there will be too many groups overtime and I need to clean them.

I have another observable, that emits value, when ResourceId becomes deprecated and can be removed.

How to remove specific groups produced by GroupBy over time to avoid memory leak?

I'm have something TakeUntil in mind:

var valueChangesObs = events
  .GroupBy(x => x.ResourceId)
  .TakeUntil(group => g)) 
  .SelectMany(group => group
        .DistinctUntilChanged(x => x.ResouceValue)
        .TakeUntil(x => resourceDeprecatedObservable.First(y => y.ResourceId = x.ResourceId))); 
Share Improve this question edited Mar 12 at 9:30 Liero asked Mar 12 at 9:01 LieroLiero 27.5k41 gold badges179 silver badges337 bronze badges 3
  • 1 How to remove specific groups produces by GroupBy over time to avoid memory leak? - since you say specific groups, what is the specification? and why isn't a simple Where sufficient? e.g. events.Where(x => IsResourceIdGood(x.ResourceId)).GroupBy(x => x.ResourceId) – Rand Random Commented Mar 12 at 9:09
  • They will become deprecated later at some point in time, for example when ResourceDeprecated event is emited – Liero Commented Mar 12 at 9:29
  • In other words, the groups (group = resource) are valid when they are created, but becames invalid, when resourec becomes invalid (e.g. resource is deleted from database) so no further events for that resource makes sense – Liero Commented Mar 12 at 9:31
Add a comment  | 

1 Answer 1

Reset to default 0

Use the .GroupByUntil operator

发布评论

评论列表(0)

  1. 暂无评论