admin管理员组

文章数量:1393577

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

本文标签: cHow to clean groups from produced by GroupByStack Overflow