BewareMyPower opened a new pull request, #54:
URL: https://github.com/apache/pulsar-client-cpp/pull/54
### Motivation
When a producer or consumer is closed, the reference is still stored in
`ClientImpl`, which causes the memory leak.
### Modifications
In `ClientImpl`, use `SynchronizedHashMap` to store references of producers
and consumers. The key is the pointer, the value is the `weak_ptr` objects.
Then, add `cleanupProducer` and `cleanupConsumer` methods to remove a specific
reference for a given pointer.
To call these two methods, this PR does a refactoring that all `ClientImpl`
references in producer or consumer are changed to a trivial reference
`ClientImpl&` instead of a `weak_ptr`. It's because the lifetime of
`ClientImpl` should be longer than them. Using `weak_ptr` is redundant and will
increase many repeat codes like:
```c++
auto client = client_.lock();
if (client) {
client->cleanupProducer(this);
}
```
After that, unify the `shutdown` implementations for producers and
consumers, which resets some states, cancels the timers, and unregister itself
from both `ClientImpl` and `ClientConnection`. Add adding customized non-null
callback in `closeAsync` and `unsubscribeAsync`.
### Verifications
`ClientCloseTest` is added to verify the following cases:
- a single topic
- a partitioned topic (multiple topics)
- a partitioned topic with regex subscription
`ClientCloseTest` is to verify these handlers are removed from `ClientImpl`.
`testShutdown` is to verify the handlers will be closed after the owned
`Client` instance destroyed.
### Documentation
<!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
- [ ] `doc-required`
(Your PR needs to update docs and you will update later)
- [x] `doc-not-needed`
(Please explain why)
- [ ] `doc`
(Your PR contains doc changes)
- [ ] `doc-complete`
(Docs have been already added)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]