| 302 | |
| 303 | #[test] |
| 304 | fn test_bytes_drop_releases_pool() { |
| 305 | let pool = TrackingMemoryPool::default(); |
| 306 | |
| 307 | { |
| 308 | // Create a buffer with pool |
| 309 | let _buffer = unsafe { |
| 310 | let layout = |
| 311 | std::alloc::Layout::from_size_align(1024, crate::alloc::ALIGNMENT).unwrap(); |
| 312 | let ptr = std::alloc::alloc(layout); |
| 313 | assert!(!ptr.is_null()); |
| 314 | |
| 315 | let bytes = Bytes::new( |
| 316 | NonNull::new(ptr).unwrap(), |
| 317 | 1024, |
| 318 | Deallocation::Standard(layout), |
| 319 | ); |
| 320 | |
| 321 | bytes.claim(&pool); |
| 322 | bytes |
| 323 | }; |
| 324 | |
| 325 | assert_eq!(pool.used(), 1024); |
| 326 | } |
| 327 | |
| 328 | // Buffer has been dropped, memory should be released |
| 329 | assert_eq!(pool.used(), 0); |
| 330 | } |
| 331 | } |
| 332 | } |